Skip to content

Commit 510cb02

Browse files
committed
fix: fix ai in editor bug
1 parent c80e976 commit 510cb02

File tree

1 file changed

+13
-6
lines changed
  • chat2db-client/src/components/Console

1 file changed

+13
-6
lines changed

chat2db-client/src/components/Console/index.tsx

+13-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import aiServer from '@/service/ai';
1111
import { v4 as uuidv4 } from 'uuid';
1212
import { DatabaseTypeCode, ConsoleStatus } from '@/constants';
1313
import Iconfont from '../Iconfont';
14-
import { ITreeNode } from '@/typings';
14+
import { IAiConfig, ITreeNode } from '@/typings';
1515
import { IAIState } from '@/models/ai';
1616
import Popularize from '@/components/Popularize';
1717
import { handleLocalStorageSavedConsole, readLocalStorageSavedConsoleText } from '@/utils';
1818
import { chatErrorForKey, chatErrorToLogin } from '@/constants/chat';
1919
import { AiSqlSourceType } from '@/typings/ai';
2020
import i18n from '@/i18n';
21+
import configService from '@/service/config';
2122
import styles from './index.less';
2223

2324
enum IPromptType {
@@ -213,8 +214,14 @@ function Console(props: IProps) {
213214
}
214215
};
215216

216-
const handleAiChat = async (content: string, promptType: IPromptType) => {
217-
const { apiKey } = aiModel?.aiConfig || {};
217+
const handleAIChatInEditor = async (content: string, promptType: IPromptType) => {
218+
const aiConfig = await configService.getAiSystemConfig({});
219+
handleAiChat(content, promptType, aiConfig);
220+
};
221+
222+
const handleAiChat = async (content: string, promptType: IPromptType, aiConfig?: IAiConfig) => {
223+
const { apiKey, aiSqlSource } = aiConfig || props.aiModel?.aiConfig || {};
224+
const isChat2DBAi = aiSqlSource === AiSqlSourceType.CHAT2DBAI;
218225
if (!apiKey && isChat2DBAi) {
219226
handleApiKeyEmptyOrGetQrCode(true);
220227
return;
@@ -349,17 +356,17 @@ function Console(props: IProps) {
349356
{
350357
id: 'explainSQL',
351358
label: i18n('common.text.explainSQL'),
352-
action: (selectedText: string) => handleAiChat(selectedText, IPromptType.SQL_EXPLAIN),
359+
action: (selectedText: string) => handleAIChatInEditor(selectedText, IPromptType.SQL_EXPLAIN),
353360
},
354361
{
355362
id: 'optimizeSQL',
356363
label: i18n('common.text.optimizeSQL'),
357-
action: (selectedText: string) => handleAiChat(selectedText, IPromptType.SQL_OPTIMIZER),
364+
action: (selectedText: string) => handleAIChatInEditor(selectedText, IPromptType.SQL_OPTIMIZER),
358365
},
359366
{
360367
id: 'changeSQL',
361368
label: i18n('common.text.conversionSQL'),
362-
action: (selectedText: string) => handleAiChat(selectedText, IPromptType.SQL_2_SQL),
369+
action: (selectedText: string) => handleAIChatInEditor(selectedText, IPromptType.SQL_2_SQL),
363370
},
364371
];
365372

0 commit comments

Comments
 (0)