mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-10-13 19:18:14 +00:00
feat(app): lint & beautify
This commit is contained in:
@@ -6,14 +6,18 @@ export const messages = sqliteTable('messages', {
|
|||||||
id: integer('id').primaryKey(),
|
id: integer('id').primaryKey(),
|
||||||
role: text('type', { enum: ['assistant', 'user', 'source'] }).notNull(),
|
role: text('type', { enum: ['assistant', 'user', 'source'] }).notNull(),
|
||||||
chatId: text('chatId').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(),
|
messageId: text('messageId').notNull(),
|
||||||
|
|
||||||
content: text('content'),
|
content: text('content'),
|
||||||
|
|
||||||
sources: text('sources', {
|
sources: text('sources', {
|
||||||
mode: 'json',
|
mode: 'json',
|
||||||
}).$type<Document[]>().default(sql`'[]'`),
|
})
|
||||||
|
.$type<Document[]>()
|
||||||
|
.default(sql`'[]'`),
|
||||||
});
|
});
|
||||||
|
|
||||||
interface File {
|
interface File {
|
||||||
|
@@ -694,7 +694,11 @@ export const ChatProvider = ({
|
|||||||
(msg, i) => i > userMessageIndex && msg.role === 'suggestion',
|
(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);
|
const suggestions = await getSuggestions(messagesRef.current);
|
||||||
setMessages((prev) => {
|
setMessages((prev) => {
|
||||||
return [
|
return [
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
import { webSearchResponsePrompt, webSearchRetrieverFewShots, webSearchRetrieverPrompt } from './webSearch';
|
import {
|
||||||
|
webSearchResponsePrompt,
|
||||||
|
webSearchRetrieverFewShots,
|
||||||
|
webSearchRetrieverPrompt,
|
||||||
|
} from './webSearch';
|
||||||
import { writingAssistantPrompt } from './writingAssistant';
|
import { writingAssistantPrompt } from './writingAssistant';
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
webSearchResponsePrompt,
|
webSearchResponsePrompt,
|
||||||
webSearchRetrieverPrompt,
|
webSearchRetrieverPrompt,
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { BaseMessageLike } from "@langchain/core/messages";
|
import { BaseMessageLike } from '@langchain/core/messages';
|
||||||
|
|
||||||
export const webSearchRetrieverPrompt = `
|
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.
|
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>
|
</conversation>
|
||||||
<query>
|
<query>
|
||||||
What is the capital of France
|
What is the capital of France
|
||||||
</query>`
|
</query>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'assistant',
|
'assistant',
|
||||||
`<question>
|
`<question>
|
||||||
Capital of france
|
Capital of france
|
||||||
</question>`
|
</question>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'user',
|
'user',
|
||||||
@@ -30,13 +30,13 @@ Capital of france
|
|||||||
</conversation>
|
</conversation>
|
||||||
<query>
|
<query>
|
||||||
Hi, how are you?
|
Hi, how are you?
|
||||||
</query>`
|
</query>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'assistant',
|
'assistant',
|
||||||
`<question>
|
`<question>
|
||||||
not_needed
|
not_needed
|
||||||
</question>`
|
</question>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'user',
|
'user',
|
||||||
@@ -44,13 +44,13 @@ not_needed
|
|||||||
</conversation>
|
</conversation>
|
||||||
<query>
|
<query>
|
||||||
What is Docker?
|
What is Docker?
|
||||||
</query>`
|
</query>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'assistant',
|
'assistant',
|
||||||
`<question>
|
`<question>
|
||||||
What is Docker
|
What is Docker
|
||||||
</question>`
|
</question>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'user',
|
'user',
|
||||||
@@ -58,7 +58,7 @@ What is Docker
|
|||||||
</conversation>
|
</conversation>
|
||||||
<query>
|
<query>
|
||||||
Can you tell me what is X from https://example.com
|
Can you tell me what is X from https://example.com
|
||||||
</query>`
|
</query>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'assistant',
|
'assistant',
|
||||||
@@ -67,7 +67,7 @@ What is X?
|
|||||||
</question>
|
</question>
|
||||||
<links>
|
<links>
|
||||||
https://example.com
|
https://example.com
|
||||||
</links>`
|
</links>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'user',
|
'user',
|
||||||
@@ -75,7 +75,7 @@ https://example.com
|
|||||||
</conversation>
|
</conversation>
|
||||||
<query>
|
<query>
|
||||||
Summarize the content from https://example.com
|
Summarize the content from https://example.com
|
||||||
</query>`
|
</query>`,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'assistant',
|
'assistant',
|
||||||
@@ -84,8 +84,8 @@ summarize
|
|||||||
</question>
|
</question>
|
||||||
<links>
|
<links>
|
||||||
https://example.com
|
https://example.com
|
||||||
</links>`
|
</links>`,
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
export const webSearchResponsePrompt = `
|
export const webSearchResponsePrompt = `
|
||||||
|
@@ -31,7 +31,7 @@ export const searchHandlers: Record<string, MetaSearchAgent> = {
|
|||||||
}),
|
}),
|
||||||
wolframAlphaSearch: new MetaSearchAgent({
|
wolframAlphaSearch: new MetaSearchAgent({
|
||||||
activeEngines: ['wolframalpha'],
|
activeEngines: ['wolframalpha'],
|
||||||
queryGeneratorPrompt: prompts.webSearchRetrieverPrompt,
|
queryGeneratorPrompt: prompts.webSearchRetrieverPrompt,
|
||||||
responsePrompt: prompts.webSearchResponsePrompt,
|
responsePrompt: prompts.webSearchResponsePrompt,
|
||||||
queryGeneratorFewShots: prompts.webSearchRetrieverFewShots,
|
queryGeneratorFewShots: prompts.webSearchRetrieverFewShots,
|
||||||
rerank: false,
|
rerank: false,
|
||||||
|
@@ -67,7 +67,9 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||||||
ChatPromptTemplate.fromMessages([
|
ChatPromptTemplate.fromMessages([
|
||||||
['system', this.config.queryGeneratorPrompt],
|
['system', this.config.queryGeneratorPrompt],
|
||||||
...this.config.queryGeneratorFewShots,
|
...this.config.queryGeneratorFewShots,
|
||||||
['user', `
|
[
|
||||||
|
'user',
|
||||||
|
`
|
||||||
<conversation>
|
<conversation>
|
||||||
{chat_history}
|
{chat_history}
|
||||||
</conversation>
|
</conversation>
|
||||||
@@ -75,7 +77,8 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||||||
<query>
|
<query>
|
||||||
{query}
|
{query}
|
||||||
</query>
|
</query>
|
||||||
`]
|
`,
|
||||||
|
],
|
||||||
]),
|
]),
|
||||||
llm,
|
llm,
|
||||||
this.strParser,
|
this.strParser,
|
||||||
@@ -87,9 +90,9 @@ class MetaSearchAgent implements MetaSearchAgentType {
|
|||||||
const questionOutputParser = new LineOutputParser({
|
const questionOutputParser = new LineOutputParser({
|
||||||
key: 'question',
|
key: 'question',
|
||||||
});
|
});
|
||||||
|
|
||||||
const links = await linksOutputParser.parse(input);
|
const links = await linksOutputParser.parse(input);
|
||||||
let question = await questionOutputParser.parse(input) ?? input;
|
let question = (await questionOutputParser.parse(input)) ?? input;
|
||||||
|
|
||||||
if (question === 'not_needed') {
|
if (question === 'not_needed') {
|
||||||
return { query: '', docs: [] };
|
return { query: '', docs: [] };
|
||||||
|
Reference in New Issue
Block a user