feat: improve prompt

This commit is contained in:
Tianzhou Chen
2023-06-08 00:23:41 +08:00
parent a62b5d803a
commit 3f31392dc1
5 changed files with 19 additions and 25 deletions

View File

@ -1 +0,0 @@
# General bot

View File

@ -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;
},
};

View File

@ -1,2 +1 @@
export * as generalBot from "./general-bot";
export * as sqlchatBot from "./sql-chat-bot";

View File

@ -1,14 +1,24 @@
import generalBot from "../general-bot";
export default {
id: "sql-chat-bot",
name: "SQL Chat bot",
description: "The wonderful SQL Chat bot.",
avatar: "",
getPrompt: (schema?: string): string => {
const generalPrompt = generalBot.getPrompt();
const basicPrompt = `Please follow the instructions to answer the questions:
1. Set the language to the markdown code block for each code block. For example, \`SELECT * FROM table\` is SQL.`;
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}`;
const basicPrompt = [
"You are a db and SQL expert.",
'When asked for you name, you must respond with "SQL Chat".',
"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");
},
};

View File

@ -3,12 +3,12 @@ import { create } from "zustand";
import { persist } from "zustand/middleware";
import { Conversation, Id } from "@/types";
import { generateUUID } from "@/utils";
import { GeneralBotId, SQLChatBotId } from ".";
import { SQLChatBotId } from ".";
const getDefaultConversation = (): Conversation => {
return {
id: generateUUID(),
assistantId: GeneralBotId,
assistantId: SQLChatBotId,
title: dayjs().format("LTS"),
createdAt: Date.now(),
};
@ -89,11 +89,7 @@ export const useConversationStore = create<ConversationState>()(
let state = persistedState as ConversationState;
if (version === 0) {
for (const conversation of state.conversationList) {
if (!conversation.connectionId) {
conversation.assistantId = "general-bot";
} else {
conversation.assistantId = "sql-chat-bot";
}
conversation.assistantId = SQLChatBotId;
}
state.currentConversationId = undefined;
}