From bf1c026666ba8955563138d33e7c71c4f9df980f Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 9 Jan 2024 14:33:04 -0800 Subject: [PATCH] feat: better rag context management --- src/routes/(app)/+page.svelte | 16 +++++++++++----- src/routes/(app)/c/[id]/+page.svelte | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index 65316941..8191b536 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -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, diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index 4305882f..aeffa000 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -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,