From 5860a6dcf25b691213b35ddd99f1f3bd2fe5fe33 Mon Sep 17 00:00:00 2001 From: Srujan Gurram Date: Mon, 12 Feb 2024 00:29:56 +0530 Subject: [PATCH] Replace system prompt with a shorter description, and update the content of the human message based on whether there are files or not --- src/config/prompts/index.ts | 5 ++--- src/hooks/useChatCompletion.ts | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/config/prompts/index.ts b/src/config/prompts/index.ts index 7c1922b3..c403bf5a 100644 --- a/src/config/prompts/index.ts +++ b/src/config/prompts/index.ts @@ -1,8 +1,7 @@ import endent from 'endent' -export const SYSTEM_PROMPT = `You are Syncia, a chatbot in browser docked to right side of the screen. - if you find [To bot] in the prompt, it means you should follow that point while generating answer but not as part of answer unless specified. - Your knowledge is limited to year 2021.` +export const SYSTEM_PROMPT = + 'You are Syncia, a chatbot in browser docked to right side of the screen.' export const getTransformedPrompt = (prompt: string, selectedText: string) => { return endent` diff --git a/src/hooks/useChatCompletion.ts b/src/hooks/useChatCompletion.ts index 0f7d7a29..a9f28573 100644 --- a/src/hooks/useChatCompletion.ts +++ b/src/hooks/useChatCompletion.ts @@ -107,22 +107,27 @@ export const useChatCompletion = ({ new SystemMessage(systemPrompt), ...previousMessages, new HumanMessage({ - content: [ - { type: 'text', text: expandedQuery }, - ...(message.files.length > 0 - ? await Promise.all( - message.files.map(async (file) => { - return { - type: 'image_url', - image_url: file.src, - } as const - }), - ) - : []), - ], + content: + message.files.length > 0 + ? [ + { type: 'text', text: expandedQuery }, + ...(message.files.length > 0 + ? await Promise.all( + message.files.map(async (file) => { + return { + type: 'image_url', + image_url: file.src, + } as const + }), + ) + : []), + ] + : expandedQuery, }), ] + console.log(JSON.stringify(messages, null, 2)) + await llm.invoke(messages, options) } catch (e) { setError(e as Error)