From c859912eab44f2556969953e542a24f7b07c772d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=A8=E7=BC=A8?= Date: Fri, 15 Nov 2024 18:06:43 +0800 Subject: [PATCH] feat: fix the bot build (#477) --- client/app/factory/edit/page.tsx | 8 +++++++- client/app/services/BotsController.ts | 17 +++++++---------- package.json | 2 +- server/agent/prompts/bot_builder.py | 6 ++++++ server/agent/tools/bot_builder.py | 2 +- server/bot/router.py | 9 ++++----- server/core/type_class/bot.py | 1 + 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/client/app/factory/edit/page.tsx b/client/app/factory/edit/page.tsx index fa873421..07db88d1 100644 --- a/client/app/factory/edit/page.tsx +++ b/client/app/factory/edit/page.tsx @@ -23,6 +23,7 @@ import SaveIcon from '@/public/icons/SaveIcon'; import { useBot } from '@/app/contexts/BotContext'; import useUser from '@/app/hooks/useUser'; import Knowledge from './components/Knowledge'; +import { useGlobal } from '@/app/contexts/GlobalContext'; import KnowledgeBtn from './components/KnowledgeBtn'; import { BotTaskProvider } from './components/TaskContext'; import { useSearchParams } from 'next/navigation'; @@ -40,6 +41,8 @@ enum ConfigTypeEnum { MANUAL_CONFIG = 'MANUAL_CONFIG', } export default function Edit() { + const { language } = useGlobal(); + const { botProfile, setBotProfile } = useBot(); const { user, status } = useUser(); const router = useRouter(); @@ -310,7 +313,10 @@ export default function Edit() { startContent={} isLoading={createBotLoading} onClick={() => { - getBotInfoByRepoName(botProfile?.repoName!); + getBotInfoByRepoName({ + repo_name: botProfile?.repoName!, + lang: language, + }); }} > {I18N.edit.page.chongXinShengChengPei} diff --git a/client/app/services/BotsController.ts b/client/app/services/BotsController.ts index d00921c6..34b2e53b 100644 --- a/client/app/services/BotsController.ts +++ b/client/app/services/BotsController.ts @@ -61,16 +61,13 @@ export async function updateBot(profile: BotProfile) { } // Get Bot Info by Repo Name -export async function getBotInfoByRepoName( - repo_name: string, - starters?: string[], - hello_message?: string, -) { - return axios.post(`${apiDomain}/api/bot/config/generator`, { - repo_name, - starters: starters ?? [], - hello_message, - }); +export async function getBotInfoByRepoName(params: { + repo_name: string; + lang?: string; + starters?: string[]; + hello_message?: string; +}) { + return axios.post(`${apiDomain}/api/bot/config/generator`, params); } export async function getChunkList( diff --git a/package.json b/package.json index a45f50d4..2cc59f55 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "client": "cd client && yarn run dev", "assistant": "cd assistant && yarn run dev", "server": "cd server && ./venv/bin/python3 -m uvicorn main:app --reload", - "env:pull": "server/venv/bin/python3 scripts/envs.py pull", + "env:pull": "cd server && ./venv/bin/python3 scripts/envs.py pull", "client:server": "concurrently \"yarn run server\" \"yarn run client\"", "assistant:server": "concurrently \"yarn run server\" \"yarn run assistant\"", "build:docker": "docker build -t petercat .", diff --git a/server/agent/prompts/bot_builder.py b/server/agent/prompts/bot_builder.py index 05757bb9..5502aeb9 100644 --- a/server/agent/prompts/bot_builder.py +++ b/server/agent/prompts/bot_builder.py @@ -14,9 +14,15 @@ Skill 2: Create a Q&A Bot +- Generate the corresponding prompt questions and greetings based on the GitHub Repository Name and the language used by the user when interacting with you. For example, the repository name is 'petercat': +The starters array contains questions like: ["Tell me about the project petercat"] +The hello_message is: "👋🏻 Hello, I’m petercat. I'm your personal Q&A bot. I’m here to assist you with any questions about this project. Feel free to ask me anything!" +The hello_message should start with an introduction of the bot. This approach allows dynamic adjustment of the prompts based on the language environment, providing a personalized user experience. + - Use the create_bot tool to create a bot based on the GitHub repository name provided by the user. - The uid of the current user is {user_id} + Skill 3: Modify Bot Configuration - Utilize the edit_bot tool to modify the bot's configuration information based on the user's description. diff --git a/server/agent/tools/bot_builder.py b/server/agent/tools/bot_builder.py index e0a60cdf..50773d6c 100644 --- a/server/agent/tools/bot_builder.py +++ b/server/agent/tools/bot_builder.py @@ -19,7 +19,7 @@ async def create_bot( """ Create a bot based on the specified GitHub repository. - :param repo_name: The full name of the GitHub repository (e.g., "ant-design/ ant-design"). + :param repo_name: The full name of the GitHub repository (e.g., "ant-design/ant-design"). :param uid: The unique identifier of the bot owner. :param starters: Optional. A list of opening dialogue prompts (e.g., ["介绍一下项目", "快速上手", "贡献指南"]). :param hello_message: Optional. A custom hello message for the bot. diff --git a/server/bot/router.py b/server/bot/router.py index dbddb850..11061497 100644 --- a/server/bot/router.py +++ b/server/bot/router.py @@ -137,14 +137,13 @@ async def bot_generator( request: Request, bot_data: BotCreateRequest, user_id: Annotated[str | None, Depends(get_user_id)] = None, - lang: str = Query("en", description="Language of the bot"), ): default_starters = [ - request.state.i18n.get_text("starter0", lang), - request.state.i18n.get_text("starter1", lang), - request.state.i18n.get_text("starter2", lang), + request.state.i18n.get_text("starter0", bot_data.lang), + request.state.i18n.get_text("starter1", bot_data.lang), + request.state.i18n.get_text("starter2", bot_data.lang), ] - default_hello_message = request.state.i18n.get_text("hello_message", lang) + default_hello_message = request.state.i18n.get_text("hello_message", bot_data.lang) starters = bot_data.starters if bot_data.starters else default_starters hello_message = ( bot_data.hello_message if bot_data.hello_message else default_hello_message diff --git a/server/core/type_class/bot.py b/server/core/type_class/bot.py index 0e549c40..bce04d48 100644 --- a/server/core/type_class/bot.py +++ b/server/core/type_class/bot.py @@ -6,6 +6,7 @@ class BotCreateRequest(BaseModel): repo_name: str starters: Optional[List[str]] = None hello_message: Optional[str] = None + lang: Optional[str] = "en" class BotDeployRequest(BaseModel):