diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 642708e..9a017da 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -6,14 +6,18 @@ export const messages = sqliteTable('messages', { id: integer('id').primaryKey(), role: text('type', { enum: ['assistant', 'user', 'source'] }).notNull(), chatId: text('chatId').notNull(), - createdAt: text('createdAt').notNull().default(sql`CURRENT_TIMESTAMP`), + createdAt: text('createdAt') + .notNull() + .default(sql`CURRENT_TIMESTAMP`), messageId: text('messageId').notNull(), content: text('content'), sources: text('sources', { mode: 'json', - }).$type().default(sql`'[]'`), + }) + .$type() + .default(sql`'[]'`), }); interface File { diff --git a/src/lib/hooks/useChat.tsx b/src/lib/hooks/useChat.tsx index 0211237..a28a53d 100644 --- a/src/lib/hooks/useChat.tsx +++ b/src/lib/hooks/useChat.tsx @@ -694,7 +694,11 @@ export const ChatProvider = ({ (msg, i) => i > userMessageIndex && msg.role === 'suggestion', ); - if (sourceMessage && sourceMessage.sources.length > 0 && suggestionMessageIndex == -1) { + if ( + sourceMessage && + sourceMessage.sources.length > 0 && + suggestionMessageIndex == -1 + ) { const suggestions = await getSuggestions(messagesRef.current); setMessages((prev) => { return [ diff --git a/src/lib/prompts/index.ts b/src/lib/prompts/index.ts index 3b849ed..fd1a85a 100644 --- a/src/lib/prompts/index.ts +++ b/src/lib/prompts/index.ts @@ -1,7 +1,10 @@ -import { webSearchResponsePrompt, webSearchRetrieverFewShots, webSearchRetrieverPrompt } from './webSearch'; +import { + webSearchResponsePrompt, + webSearchRetrieverFewShots, + webSearchRetrieverPrompt, +} from './webSearch'; import { writingAssistantPrompt } from './writingAssistant'; - export default { webSearchResponsePrompt, webSearchRetrieverPrompt, diff --git a/src/lib/prompts/webSearch.ts b/src/lib/prompts/webSearch.ts index 6e2002b..b99b542 100644 --- a/src/lib/prompts/webSearch.ts +++ b/src/lib/prompts/webSearch.ts @@ -1,4 +1,4 @@ -import { BaseMessageLike } from "@langchain/core/messages"; +import { BaseMessageLike } from '@langchain/core/messages'; export const webSearchRetrieverPrompt = ` You are an AI question rephraser. You will be given a conversation and a follow-up question, you will have to rephrase the follow up question so it is a standalone question and can be used by another LLM to search the web for information to answer it. @@ -16,13 +16,13 @@ export const webSearchRetrieverFewShots: BaseMessageLike[] = [ What is the capital of France -` +`, ], [ 'assistant', ` Capital of france -` +`, ], [ 'user', @@ -30,13 +30,13 @@ Capital of france Hi, how are you? -` +`, ], [ 'assistant', ` not_needed -` +`, ], [ 'user', @@ -44,13 +44,13 @@ not_needed What is Docker? -` +`, ], [ 'assistant', ` What is Docker -` +`, ], [ 'user', @@ -58,7 +58,7 @@ What is Docker Can you tell me what is X from https://example.com -` +`, ], [ 'assistant', @@ -67,7 +67,7 @@ What is X? https://example.com -` +`, ], [ 'user', @@ -75,7 +75,7 @@ https://example.com Summarize the content from https://example.com -` +`, ], [ 'assistant', @@ -84,8 +84,8 @@ summarize https://example.com -` - ] +`, + ], ]; export const webSearchResponsePrompt = ` diff --git a/src/lib/search/index.ts b/src/lib/search/index.ts index f5cb8cb..8eb8ab0 100644 --- a/src/lib/search/index.ts +++ b/src/lib/search/index.ts @@ -31,7 +31,7 @@ export const searchHandlers: Record = { }), wolframAlphaSearch: new MetaSearchAgent({ activeEngines: ['wolframalpha'], - queryGeneratorPrompt: prompts.webSearchRetrieverPrompt, + queryGeneratorPrompt: prompts.webSearchRetrieverPrompt, responsePrompt: prompts.webSearchResponsePrompt, queryGeneratorFewShots: prompts.webSearchRetrieverFewShots, rerank: false, diff --git a/src/lib/search/metaSearchAgent.ts b/src/lib/search/metaSearchAgent.ts index dcf0244..b555b8a 100644 --- a/src/lib/search/metaSearchAgent.ts +++ b/src/lib/search/metaSearchAgent.ts @@ -67,7 +67,9 @@ class MetaSearchAgent implements MetaSearchAgentType { ChatPromptTemplate.fromMessages([ ['system', this.config.queryGeneratorPrompt], ...this.config.queryGeneratorFewShots, - ['user', ` + [ + 'user', + ` {chat_history} @@ -75,7 +77,8 @@ class MetaSearchAgent implements MetaSearchAgentType { {query} - `] + `, + ], ]), llm, this.strParser, @@ -87,9 +90,9 @@ class MetaSearchAgent implements MetaSearchAgentType { const questionOutputParser = new LineOutputParser({ key: 'question', }); - + const links = await linksOutputParser.parse(input); - let question = await questionOutputParser.parse(input) ?? input; + let question = (await questionOutputParser.parse(input)) ?? input; if (question === 'not_needed') { return { query: '', docs: [] };