Merge pull request #439 from ollama-webui/rag-context-management

feat: better rag context management
This commit is contained in:
Timothy Jaeryang Baek 2024-01-09 14:34:37 -08:00 committed by GitHub
commit 358f79f533
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View file

@ -288,9 +288,9 @@
...messages
]
.filter((message) => message)
.map((message) => ({
.map((message, idx, arr) => ({
role: message.role,
content: message?.raContent ?? message.content,
content: arr.length - 2 !== idx ? message.content : message?.raContent ?? message.content,
...(message.files && {
images: message.files
.filter((file) => file.type === 'image')
@ -472,14 +472,17 @@
...messages
]
.filter((message) => message)
.map((message) => ({
.map((message, idx, arr) => ({
role: message.role,
...(message.files
? {
content: [
{
type: 'text',
text: message?.raContent ?? message.content
text:
arr.length - 1 !== idx
? message.content
: message?.raContent ?? message.content
},
...message.files
.filter((file) => file.type === 'image')
@ -491,7 +494,10 @@
}))
]
}
: { content: message?.raContent ?? message.content })
: {
content:
arr.length - 1 !== idx ? message.content : message?.raContent ?? message.content
})
})),
seed: $settings?.options?.seed ?? undefined,
stop: $settings?.options?.stop ?? undefined,

View file

@ -299,9 +299,9 @@
...messages
]
.filter((message) => message)
.map((message) => ({
.map((message, idx, arr) => ({
role: message.role,
content: message?.raContent ?? message.content,
content: arr.length - 2 !== idx ? message.content : message?.raContent ?? message.content,
...(message.files && {
images: message.files
.filter((file) => file.type === 'image')
@ -483,14 +483,17 @@
...messages
]
.filter((message) => message)
.map((message) => ({
.map((message, idx, arr) => ({
role: message.role,
...(message.files
? {
content: [
{
type: 'text',
text: message?.raContent ?? message.content
text:
arr.length - 1 !== idx
? message.content
: message?.raContent ?? message.content
},
...message.files
.filter((file) => file.type === 'image')
@ -502,7 +505,10 @@
}))
]
}
: { content: message?.raContent ?? message.content })
: {
content:
arr.length - 1 !== idx ? message.content : message?.raContent ?? message.content
})
})),
seed: $settings?.options?.seed ?? undefined,
stop: $settings?.options?.stop ?? undefined,