feat(app): lint & beautify

This commit is contained in:
ItzCrazyKns
2025-09-25 18:57:21 +05:30
parent 5f18fc1d22
commit 984163bbbc
6 changed files with 36 additions and 22 deletions

View File

@@ -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<Document[]>().default(sql`'[]'`),
})
.$type<Document[]>()
.default(sql`'[]'`),
});
interface File {

View File

@@ -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 [

View File

@@ -1,7 +1,10 @@
import { webSearchResponsePrompt, webSearchRetrieverFewShots, webSearchRetrieverPrompt } from './webSearch';
import {
webSearchResponsePrompt,
webSearchRetrieverFewShots,
webSearchRetrieverPrompt,
} from './webSearch';
import { writingAssistantPrompt } from './writingAssistant';
export default {
webSearchResponsePrompt,
webSearchRetrieverPrompt,

View File

@@ -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[] = [
</conversation>
<query>
What is the capital of France
</query>`
</query>`,
],
[
'assistant',
`<question>
Capital of france
</question>`
</question>`,
],
[
'user',
@@ -30,13 +30,13 @@ Capital of france
</conversation>
<query>
Hi, how are you?
</query>`
</query>`,
],
[
'assistant',
`<question>
not_needed
</question>`
</question>`,
],
[
'user',
@@ -44,13 +44,13 @@ not_needed
</conversation>
<query>
What is Docker?
</query>`
</query>`,
],
[
'assistant',
`<question>
What is Docker
</question>`
</question>`,
],
[
'user',
@@ -58,7 +58,7 @@ What is Docker
</conversation>
<query>
Can you tell me what is X from https://example.com
</query>`
</query>`,
],
[
'assistant',
@@ -67,7 +67,7 @@ What is X?
</question>
<links>
https://example.com
</links>`
</links>`,
],
[
'user',
@@ -75,7 +75,7 @@ https://example.com
</conversation>
<query>
Summarize the content from https://example.com
</query>`
</query>`,
],
[
'assistant',
@@ -84,8 +84,8 @@ summarize
</question>
<links>
https://example.com
</links>`
]
</links>`,
],
];
export const webSearchResponsePrompt = `

View File

@@ -31,7 +31,7 @@ export const searchHandlers: Record<string, MetaSearchAgent> = {
}),
wolframAlphaSearch: new MetaSearchAgent({
activeEngines: ['wolframalpha'],
queryGeneratorPrompt: prompts.webSearchRetrieverPrompt,
queryGeneratorPrompt: prompts.webSearchRetrieverPrompt,
responsePrompt: prompts.webSearchResponsePrompt,
queryGeneratorFewShots: prompts.webSearchRetrieverFewShots,
rerank: false,

View File

@@ -67,7 +67,9 @@ class MetaSearchAgent implements MetaSearchAgentType {
ChatPromptTemplate.fromMessages([
['system', this.config.queryGeneratorPrompt],
...this.config.queryGeneratorFewShots,
['user', `
[
'user',
`
<conversation>
{chat_history}
</conversation>
@@ -75,7 +77,8 @@ class MetaSearchAgent implements MetaSearchAgentType {
<query>
{query}
</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: [] };