fix: display default prompt in the schema drawer if general bot is selected

This commit is contained in:
Tianzhou Chen
2023-06-07 23:44:42 +08:00
parent 8434d83133
commit 3b276ce9a6

View File

@ -22,14 +22,11 @@ const SchemaDrawer = (props: Props) => {
const getPrompt = async () => { const getPrompt = async () => {
if (!currentConversation) return; if (!currentConversation) return;
if (!connectionStore.currentConnectionCtx?.database) return;
const promptGenerator = getPromptGeneratorOfAssistant(getAssistantById(currentConversation.assistantId)!); const promptGenerator = getPromptGeneratorOfAssistant(getAssistantById(currentConversation.assistantId)!);
let dbPrompt = promptGenerator(); let dbPrompt = promptGenerator();
if (connectionStore.currentConnectionCtx?.database) {
const maxToken = getModel(settingStore.setting.openAIApiConfig?.model || "").max_token; const maxToken = getModel(settingStore.setting.openAIApiConfig?.model || "").max_token;
const schemaList = await connectionStore.getOrFetchDatabaseSchema(connectionStore.currentConnectionCtx?.database); const schemaList = await connectionStore.getOrFetchDatabaseSchema(connectionStore.currentConnectionCtx?.database);
if (connectionStore.currentConnectionCtx?.database) {
try {
dbPrompt = generateDbPromptFromContext( dbPrompt = generateDbPromptFromContext(
promptGenerator, promptGenerator,
schemaList, schemaList,
@ -37,11 +34,8 @@ const SchemaDrawer = (props: Props) => {
currentConversation.selectedTablesName || [], currentConversation.selectedTablesName || [],
maxToken maxToken
); );
}
setPrompt(dbPrompt); setPrompt(dbPrompt);
} catch (error: any) {
toast.error(error.message);
}
}
}; };
useEffect(() => { useEffect(() => {