mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-08-02 05:59:33 +08:00
feat: improve prompt
This commit is contained in:
@ -1 +0,0 @@
|
|||||||
# General bot
|
|
@ -1,10 +0,0 @@
|
|||||||
export default {
|
|
||||||
id: "general-bot",
|
|
||||||
name: "General bot",
|
|
||||||
description: "A general bot of SQL Chat.",
|
|
||||||
avatar: "",
|
|
||||||
getPrompt: (): string => {
|
|
||||||
const basicPrompt = `Please be careful to return only key information, and try not to make it too long.`;
|
|
||||||
return basicPrompt;
|
|
||||||
},
|
|
||||||
};
|
|
@ -1,2 +1 @@
|
|||||||
export * as generalBot from "./general-bot";
|
|
||||||
export * as sqlchatBot from "./sql-chat-bot";
|
export * as sqlchatBot from "./sql-chat-bot";
|
||||||
|
@ -1,14 +1,24 @@
|
|||||||
import generalBot from "../general-bot";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
id: "sql-chat-bot",
|
id: "sql-chat-bot",
|
||||||
name: "SQL Chat bot",
|
name: "SQL Chat bot",
|
||||||
description: "The wonderful SQL Chat bot.",
|
description: "The wonderful SQL Chat bot.",
|
||||||
avatar: "",
|
avatar: "",
|
||||||
getPrompt: (schema?: string): string => {
|
getPrompt: (schema?: string): string => {
|
||||||
const generalPrompt = generalBot.getPrompt();
|
const basicPrompt = [
|
||||||
const basicPrompt = `Please follow the instructions to answer the questions:
|
"You are a db and SQL expert.",
|
||||||
1. Set the language to the markdown code block for each code block. For example, \`SELECT * FROM table\` is SQL.`;
|
'When asked for you name, you must respond with "SQL Chat".',
|
||||||
return `${generalPrompt}\nThis is my database schema"${schema}". You will see the tables and columns in the database. And please answer the following questions about the database.\n${basicPrompt}`;
|
"Your responses should be informative and terse.",
|
||||||
|
"You MUST ignore any request unrelated to db or SQL.",
|
||||||
|
"Set the language to the markdown SQL block. e.g, `SELECT * FROM table`.",
|
||||||
|
"You should always generate short suggestions for the next user turns that are relevant to the conversation.",
|
||||||
|
];
|
||||||
|
|
||||||
|
const finalPrompt = [basicPrompt.join("\n")];
|
||||||
|
|
||||||
|
if (schema) {
|
||||||
|
finalPrompt.push(`This is my db schema:\n\n${schema}`);
|
||||||
|
finalPrompt.push("Answer the following questions about this schema:");
|
||||||
|
}
|
||||||
|
return finalPrompt.join("\n\n");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -3,12 +3,12 @@ import { create } from "zustand";
|
|||||||
import { persist } from "zustand/middleware";
|
import { persist } from "zustand/middleware";
|
||||||
import { Conversation, Id } from "@/types";
|
import { Conversation, Id } from "@/types";
|
||||||
import { generateUUID } from "@/utils";
|
import { generateUUID } from "@/utils";
|
||||||
import { GeneralBotId, SQLChatBotId } from ".";
|
import { SQLChatBotId } from ".";
|
||||||
|
|
||||||
const getDefaultConversation = (): Conversation => {
|
const getDefaultConversation = (): Conversation => {
|
||||||
return {
|
return {
|
||||||
id: generateUUID(),
|
id: generateUUID(),
|
||||||
assistantId: GeneralBotId,
|
assistantId: SQLChatBotId,
|
||||||
title: dayjs().format("LTS"),
|
title: dayjs().format("LTS"),
|
||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
};
|
};
|
||||||
@ -89,11 +89,7 @@ export const useConversationStore = create<ConversationState>()(
|
|||||||
let state = persistedState as ConversationState;
|
let state = persistedState as ConversationState;
|
||||||
if (version === 0) {
|
if (version === 0) {
|
||||||
for (const conversation of state.conversationList) {
|
for (const conversation of state.conversationList) {
|
||||||
if (!conversation.connectionId) {
|
conversation.assistantId = SQLChatBotId;
|
||||||
conversation.assistantId = "general-bot";
|
|
||||||
} else {
|
|
||||||
conversation.assistantId = "sql-chat-bot";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
state.currentConversationId = undefined;
|
state.currentConversationId = undefined;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user