feat: better rag context management

This commit is contained in:
Timothy J. Baek 2024-01-09 14:33:04 -08:00
parent 51eb2645b7
commit bf1c026666
2 changed files with 22 additions and 10 deletions

View file

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

View file

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