diff --git a/ui/web/public/locales/en/AI.json b/ui/web/public/locales/en/AI.json deleted file mode 100644 index 86889286..00000000 --- a/ui/web/public/locales/en/AI.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "clean": "Clear chat history", - "hello": "I am Yuan AI assistant. I can help you write professional quantitative model code. Please explain your model ideas and rules.", - "input_placeholder": "Ctrl / ⌘ ↵ can be quickly sent", - "login_first": "Login to use", - "send": "Send", - "server_error": "Service abnormality, please try again later", - "unsupported_message": "[Viewing this message is not supported, please update and try again]" -} diff --git a/ui/web/public/locales/zh-Hans/AI.json b/ui/web/public/locales/zh-Hans/AI.json deleted file mode 100644 index fefbd4f3..00000000 --- a/ui/web/public/locales/zh-Hans/AI.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "clean": "清理聊天记录", - "hello": "我是 Yuan AI 助理,可以帮助您编写专业的量化模型代码,请说明您的模型思路与规则。", - "input_placeholder": "Ctrl / ⌘ + ↵ 可以快捷发送", - "login_first": "请登录后使用", - "send": "发送", - "server_error": "服务异常,请稍后再试", - "unsupported_message": "[不支持查看该消息,请更新后重试]" -} diff --git a/ui/web/src/modules/AI/AI.tsx b/ui/web/src/modules/AI/AI.tsx deleted file mode 100644 index 9df717e0..00000000 --- a/ui/web/src/modules/AI/AI.tsx +++ /dev/null @@ -1,187 +0,0 @@ -import { IconDelete, IconSend, IconUser } from '@douyinfe/semi-icons'; -import { Avatar, Button, Space, TextArea } from '@douyinfe/semi-ui'; -import { format } from 'date-fns'; -import { t } from 'i18next'; -import { useObservableState } from 'observable-hooks'; -import { useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { agentConf$ } from '../Agent/AgentConfForm'; -import { executeCommand, registerCommand } from '../CommandCenter'; -import { fs } from '../FileSystem/api'; -import { createPersistBehaviorSubject } from '../FileSystem/createPersistBehaviorSubject'; -import { registerPage, usePageViewport } from '../Pages'; -import { authState$ } from '../SupaBase'; -import './LUI.css'; - -interface IMessage { - role: 'user' | 'assistant'; - content: string; -} - -const historyMessages$ = createPersistBehaviorSubject('history-messages', []); -const pushHistoryMessages = (...messages: IMessage[]) => { - historyMessages$.next([...(historyMessages$.value || []), ...messages]); -}; - -registerCommand('AI.clean', () => { - historyMessages$.next([ - { - role: 'assistant', - content: t('AI:hello'), - }, - ]); -}); - -registerPage('AI', () => { - const { t } = useTranslation('AI'); - const viewport = usePageViewport(); - const width = viewport?.w ?? Infinity; - const [isLoading, setLoading] = useState(false); - - const authState = useObservableState(authState$); - - const messages = useObservableState(historyMessages$) || []; - const [userInput, setUserInput] = useState(''); - - useEffect(() => { - if (messages.length === 0) { - executeCommand('AI.clean'); - } - }, []); - - const handleSend = async () => { - if (!authState) { - executeCommand('Login'); - return; - } - - const message = userInput.trim(); - setUserInput(''); - if (!message) return; - pushHistoryMessages({ role: 'user', content: message }); - // - setLoading(true); - // ISSUE: Request FS first - try { - if (!(await fs.stat('/AIGC')).isDirectory()) { - throw Error('Not a directory'); - } - } catch (e) { - try { - await fs.mkdir('/AIGC'); - } catch (e) { - // - } - } - - try { - const question = message; - - if (authState) { - const resp = await fetch('https://api-dev.ntnl.io/assistant', { - mode: 'cors', - method: 'POST', - body: JSON.stringify({ content: question }), - credentials: 'include', - // TODO: use cookies - headers: { - 'yuan-refresh-token': authState.refresh_token, - 'yuan-access-token': authState.access_token, - 'Content-Type': 'application/json', - }, - }).then( - (x) => x.json(), - () => { - pushHistoryMessages({ - role: 'assistant', - content: t('server_error'), - }); - }, - ); - if (resp.data.messageType === 'CODE') { - pushHistoryMessages( - { - role: 'assistant', - content: resp.data.message.remark, - }, - { - role: 'assistant', - content: resp.data.message.code, - }, - ); - - const filename = `/AIGC/${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}.ts`; - const code = [ - `// User Prompt`, - ...question.split('\n').map((x) => '// ' + x), - `// Assistant Note:`, - ...(resp.data.message.remark as string).split('\n').map((x) => '// ' + x), - `// AIGC Result:`, - resp.data.message.code, - ].join('\n'); - await fs.writeFile(filename, code); - - pushHistoryMessages({ role: 'assistant', content: `${t('common:saved')}: ${filename}` }); - agentConf$.next({ ...agentConf$.value, entry: filename }); - gtag('event', 'ai_agent_complete'); - } else { - pushHistoryMessages({ role: 'assistant', content: resp.data.message.content }); - } - gtag('event', 'ai_complete', { type: resp.data.messageType }); - } - } catch (e) { - gtag('event', 'ai_error', { message: `${e}` }); - } - setLoading(false); - }; - return ( - -
- {messages.map((message) => ( -
- {message.role === 'assistant' ? 'Y' : 'U'} -
-              {typeof message.content === 'string' ? message.content : t('unsupported_message')}
-            
-
- ))} -
- {messages.length > 0 && ( - - )} - -