From 2f97ecb93a483e1816b4723757d7acca73fddf2c Mon Sep 17 00:00:00 2001 From: yingying Date: Wed, 12 Jun 2024 03:15:36 +0800 Subject: [PATCH] feat: enable to generate a random avatar for the bot --- client/app/factory/edit/[id]/page.tsx | 34 +++++++++++++----- .../factory/edit/components/BotCreateFrom.tsx | 10 ++++-- client/app/hooks/useBot.ts | 2 +- client/app/interface/index.ts | 1 + client/app/services/BotsController.ts | 18 +++++++--- client/public/images/avatar0.png | Bin 0 -> 248135 bytes client/public/images/avatar1.png | Bin 0 -> 517748 bytes client/public/images/avatar2.png | Bin 0 -> 300387 bytes client/public/images/avatar3.png | Bin 0 -> 416761 bytes client/public/images/avatar4.png | Bin 0 -> 293097 bytes client/public/images/avatar5.png | Bin 0 -> 548088 bytes client/public/images/avatar6.png | Bin 0 -> 275876 bytes client/public/images/avatar7.png | Bin 0 -> 696175 bytes client/public/images/avatar8.png | Bin 0 -> 681324 bytes client/public/images/avatar9.png | Bin 0 -> 299457 bytes server/bot/builder.py | 8 ++--- server/routers/bot.py | 1 - server/tools/bot_builder.py | 2 -- server/type_class/bot.py | 3 +- 19 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 client/public/images/avatar0.png create mode 100644 client/public/images/avatar1.png create mode 100644 client/public/images/avatar2.png create mode 100644 client/public/images/avatar3.png create mode 100644 client/public/images/avatar4.png create mode 100644 client/public/images/avatar5.png create mode 100644 client/public/images/avatar6.png create mode 100644 client/public/images/avatar7.png create mode 100644 client/public/images/avatar8.png create mode 100644 client/public/images/avatar9.png diff --git a/client/app/factory/edit/[id]/page.tsx b/client/app/factory/edit/[id]/page.tsx index a7a7e91a..2fda74b7 100644 --- a/client/app/factory/edit/[id]/page.tsx +++ b/client/app/factory/edit/[id]/page.tsx @@ -22,6 +22,7 @@ export default function Edit({ params }: { params: { id: string } }) { const [botProfile, setBotProfile] = useImmer({ id: '', avatar: '', + gitAvatar: '', name: 'Untitled', description: '', prompt: '', @@ -49,8 +50,8 @@ export default function Edit({ params }: { params: { id: string } }) { } = useBotCreate(); const isEdit = useMemo( - () => !!params?.id && params?.id !== 'new', - [params?.id], + () => (!!params?.id && params?.id !== 'new') || !!botProfile?.id, + [params?.id, botProfile?.id], ); const { data: config, isLoading } = useBotConfig(params?.id, isEdit); @@ -89,9 +90,19 @@ export default function Edit({ params }: { params: { id: string } }) { }, [createError]); useEffect(() => { - if (createResponseData) { + const botInfo = createResponseData?.[0]; + if (!isEmpty(botInfo)) { setBotProfile?.((draft) => { - draft.id = createResponseData; + draft.repoName = botProfile.repoName; + draft.id = botInfo.id; + draft.name = botInfo.name; + draft.avatar = botInfo.avatar; + draft.gitAvatar = botInfo.gitAvatar; + draft.prompt = botInfo.prompt; + draft.description = botInfo.description; + draft.starters = botInfo.starters; + draft.public = botInfo.public; + draft.helloMessage = botInfo.hello_message; }); } }, [createResponseData]); @@ -141,9 +152,9 @@ export default function Edit({ params }: { params: { id: string } }) { variant="bordered" name="repo_name" label="Github 项目名" + value={botProfile?.repoName} placeholder="请输入 GitHub 项目名称 (ORG_NAME/REPO_NAME)" labelPlacement="outside" - value={botProfile?.description} onChange={(e) => { const repoName = e.target.value; setBotProfile?.((draft) => { @@ -153,12 +164,13 @@ export default function Edit({ params }: { params: { id: string } }) { required className="mt-1 mb-6 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" /> - {isEdit ? ( + {!isEdit ? (
- {!isEdit && ( + {isEdit && ( )} @@ -216,7 +229,7 @@ export default function Edit({ params }: { params: { id: string } }) { aria-label="Options" onSelectionChange={(key) => setActiveTab(`${key}`)} classNames={{ - base: 'w-[216px] h-[36px]', + base: 'w-[230px] h-[36px]', tab: 'shadow-none w-[108px] h-[36px] px-0 py-0', tabContent: 'group-data-[selected=true]:bg-[#FAE4CB] rounded-full px-3 py-2 w-[108px] h-[36px]', @@ -291,7 +304,10 @@ export default function Edit({ params }: { params: { id: string } }) { 'https://mdn.alipayobjects.com/huamei_j8gzmo/afts/img/A*YAP3SI7MMHQAAAAAAAAAAAAADrPSAQ/original', title: botProfile?.name || 'PeterCat', }} - apiUrl={`${API_HOST}/api/chat/stream_chat`} + apiDomain={API_HOST} + apiUrl="/api/chat/stream_qa" + prompt={botProfile?.prompt} + starters={botProfile?.starters} helloMessage={botProfile?.helloMessage} /> )} diff --git a/client/app/factory/edit/components/BotCreateFrom.tsx b/client/app/factory/edit/components/BotCreateFrom.tsx index 812b11e0..07b7c708 100644 --- a/client/app/factory/edit/components/BotCreateFrom.tsx +++ b/client/app/factory/edit/components/BotCreateFrom.tsx @@ -6,6 +6,7 @@ import type { Updater } from 'use-immer'; import InputList from './InputList'; import BulbIcon from '@/public/icons/BulbIcon'; import GitHubIcon from '@/public/icons/GitHubIcon'; +import { random } from 'lodash'; interface BotFormProps { botProfile?: BotProfile; @@ -38,6 +39,11 @@ const BotCreateFrom = (props: BotFormProps) => {