import { useRequest } from 'ahooks'; import { useContext, useState } from 'react'; import { Divider, Spin, Tag } from 'antd'; import { useRouter } from 'next/navigation'; import Image from 'next/image'; import { NextPage } from 'next'; import { apiInterceptors, newDialogue, postScenes } from '@/client/api'; import ModelSelector from '@/components/chat/header/model-selector'; import { ChatContext } from '@/app/chat-context'; import { SceneResponse } from '@/types/chat'; import CompletionInput from '@/components/common/completion-input'; import { useTranslation } from 'react-i18next'; import { STORAGE_INIT_MESSAGE_KET } from '@/utils'; import Icon from '@ant-design/icons/lib/components/Icon'; import { ColorfulDB, ColorfulPlugin, ColorfulDashboard, ColorfulData, ColorfulExcel, ColorfulDoc, ColorfulChat } from '@/components/icons'; import classNames from 'classnames'; const Home: NextPage = () => { const router = useRouter(); const { model, setModel } = useContext(ChatContext); const { t } = useTranslation(); const [loading, setLoading] = useState(false); const [chatSceneLoading, setChatSceneLoading] = useState(false); const { data: scenesList = [] } = useRequest(async () => { setChatSceneLoading(true); const [, res] = await apiInterceptors(postScenes()); setChatSceneLoading(false); return res ?? []; }); const submit = async (message: string) => { setLoading(true); const [, res] = await apiInterceptors(newDialogue({ chat_mode: 'chat_normal' })); if (res) { localStorage.setItem(STORAGE_INIT_MESSAGE_KET, JSON.stringify({ id: res.conv_uid, message })); router.push(`/chat/?scene=chat_normal&id=${res.conv_uid}${model ? `&model=${model}` : ''}`); } setLoading(false); }; const handleNewChat = async (scene: SceneResponse) => { if (scene.show_disable) return; const [, res] = await apiInterceptors(newDialogue({ chat_mode: 'chat_normal' })); if (res) { router.push(`/chat?scene=${scene.chat_scene}&id=${res.conv_uid}${model ? `&model=${model}` : ''}`); } }; function renderSceneIcon(scene: string) { switch (scene) { case 'chat_knowledge': return ; case 'chat_with_db_execute': return ; case 'chat_excel': return ; case 'chat_with_db_qa': return ; case 'chat_dashboard': return ; case 'chat_agent': return ; case 'dbgpt_chat': return ; default: return null; } } return (
Revolutionizing Database Interactions with Private LLM Technology {t('Quick_Start')}
{scenesList.map((scene) => (
{ handleNewChat(scene); }} >
{renderSceneIcon(scene.chat_scene)}

{scene.scene_name} {scene.show_disable && Comming soon}

{scene.scene_describe}

))}
{ setModel(newModel); }} />
); }; export default Home;