From 067ead7afbe60daf0299d942dddb54c047e12f3d Mon Sep 17 00:00:00 2001 From: Miao Zhuang <1060950782@163.com> Date: Mon, 22 Jan 2024 10:40:55 +0800 Subject: [PATCH] fix: issues (#752) --- app/components/ColorPicker/index.tsx | 5 ++++- app/components/FileConfigSetting/index.tsx | 5 ++++- app/pages/MainPage/index.tsx | 6 +++++- app/stores/llm.ts | 4 ++-- server/api/studio/pkg/llm/importjob.go | 8 ++++---- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/components/ColorPicker/index.tsx b/app/components/ColorPicker/index.tsx index a3432659..1e26ea21 100644 --- a/app/components/ColorPicker/index.tsx +++ b/app/components/ColorPicker/index.tsx @@ -11,7 +11,7 @@ interface IProps { const ColorPicker: React.FC = (props: IProps) => { const { onChange, onChangeComplete } = props; - const handleChange = color => { + const handleChange = (color) => { if (onChange) { onChange(color); } @@ -19,6 +19,9 @@ const ColorPicker: React.FC = (props: IProps) => { const handleChangeComplete = (color, _event) => { if (onChangeComplete) { + if (_event.target.value && _event.target.value.length === 3) { + return; + } onChangeComplete(color); } }; diff --git a/app/components/FileConfigSetting/index.tsx b/app/components/FileConfigSetting/index.tsx index 96ea9548..f9fe9096 100644 --- a/app/components/FileConfigSetting/index.tsx +++ b/app/components/FileConfigSetting/index.tsx @@ -66,7 +66,10 @@ const FileConfigSetting = (props: IProps) => { const readFile = useCallback( debounce(() => { const { activeItem, setState } = state; - if (!activeItem || !(activeItem.name.indexOf('.csv') > -1)) return; + if (!activeItem || !(activeItem.name.indexOf('.csv') > -1)) { + setState({ previewContent: [] }); + return; + } setState({ loading: true }); let content = []; if (activeItem.sample !== undefined) { diff --git a/app/pages/MainPage/index.tsx b/app/pages/MainPage/index.tsx index 2773059e..fa9734c7 100644 --- a/app/pages/MainPage/index.tsx +++ b/app/pages/MainPage/index.tsx @@ -1,4 +1,4 @@ -import { Suspense } from 'react'; +import { Suspense, useEffect } from 'react'; import { Layout, Spin } from 'antd'; import { Redirect, Route, Switch } from 'react-router-dom'; import { shouldAlwaysShowWelcome } from '@app/pages/Welcome'; @@ -7,10 +7,14 @@ import { MENU_LIST, RoutesList } from './routes'; import './index.less'; import Header from './Header'; +import llm from '@app/stores/llm'; const { Content } = Layout; const MainPage = () => { const redirectPath = shouldAlwaysShowWelcome() ? '/welcome' : '/console'; + useEffect(() => { + llm.fetchConfig(); + }, []); return (
diff --git a/app/stores/llm.ts b/app/stores/llm.ts index 1ce80646..bca2eb55 100644 --- a/app/stores/llm.ts +++ b/app/stores/llm.ts @@ -83,8 +83,9 @@ class LLM { open = false; config = { maxContextLength: 2000, - url: 'https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}', + url: 'https://api.openai.com/v1/chat/completions', apiType: 'openai', + model: 'gpt-3.5-turbo', features: ['spaceSchema', 'useConsoleNGQL'], } as LLMConfig; widget: HTMLSpanElement; @@ -96,7 +97,6 @@ class LLM { editor: false, widget: false, }); - this.fetchConfig(); } fetchConfig() { diff --git a/server/api/studio/pkg/llm/importjob.go b/server/api/studio/pkg/llm/importjob.go index 96b446b6..7039f1fb 100644 --- a/server/api/studio/pkg/llm/importjob.go +++ b/server/api/studio/pkg/llm/importjob.go @@ -381,9 +381,9 @@ func (i *ImportJob) ParseText(text string) { } func (i *ImportJob) GetPrompt(text string) string { - promptTemplate := config.GetConfig().LLM.PromptTemplate - i.Prompt = strings.ReplaceAll(promptTemplate, "{userPrompt}", i.LLMJob.UserPrompt) - i.Prompt = strings.ReplaceAll(promptTemplate, "{spaceSchema}", i.SpaceSchemaString) + i.Prompt = config.GetConfig().LLM.PromptTemplate + i.Prompt = strings.ReplaceAll(i.Prompt, "{userPrompt}", i.LLMJob.UserPrompt) + i.Prompt = strings.ReplaceAll(i.Prompt, "{spaceSchema}", i.SpaceSchemaString) i.Prompt = strings.ReplaceAll(i.Prompt, "{text}", text) return i.Prompt } @@ -396,7 +396,7 @@ func (i *ImportJob) QueryBlocks(blocks []string) error { break } if IsRunningJobStopped(job.JobID) { - return nil + return fmt.Errorf("job stopped") } prompt := i.GetPrompt(block) text, err := i.Query(prompt)