From aa6ebe956986ed6c987faae89367b94dde8f7272 Mon Sep 17 00:00:00 2001 From: yingying Date: Mon, 18 Nov 2024 14:46:12 +0800 Subject: [PATCH 1/2] fix: solve the create bot --- assistant/src/Chat/index.tsx | 4 ---- assistant/src/mock/bot.mock.ts | 8 ++++++-- client/app/factory/edit/page.tsx | 5 ++++- client/app/services/BotsController.ts | 17 +++++++---------- server/agent/bot/bot_builder.py | 10 +++++----- server/agent/prompts/bot_builder.py | 4 ++-- server/bot/router.py | 20 +++++++++++++------- 7 files changed, 37 insertions(+), 31 deletions(-) diff --git a/assistant/src/Chat/index.tsx b/assistant/src/Chat/index.tsx index 1b84a912..2a1026ad 100644 --- a/assistant/src/Chat/index.tsx +++ b/assistant/src/Chat/index.tsx @@ -177,10 +177,6 @@ const Chat: FC = memo( content={
-
- 👋🏻 你好,我是{' '} - {botInfo.assistantMeta?.title || BOT_INFO.name} -
{props.message}
diff --git a/assistant/src/mock/bot.mock.ts b/assistant/src/mock/bot.mock.ts index b39be1c9..c7c24f34 100644 --- a/assistant/src/mock/bot.mock.ts +++ b/assistant/src/mock/bot.mock.ts @@ -2,6 +2,10 @@ export const BOT_INFO = { avatar: 'https://mdn.alipayobjects.com/huamei_yhboz9/afts/img/A*li7ySppF7TYAAAAAAAAAAAAADlDCAQ/original', name: 'peterCat', - helloMessage: '👋🏻 你好,我是 Peter Cat
初次见面,先自我介绍一下:我是一个开源项目的机器人。你可以通过和我对话配置一个答疑机器人。下面是一些快捷选项,你可以选择开始配置!', //开场白 - starters: ['答疑机器人需要完成哪几步的配置?', '帮我创建一个 Ant Design 答疑机器人'], //预制问题 + helloMessage: + '👋🏻 你好,我是 Peter Cat 初次见面,先自我介绍一下:我是一个开源项目的机器人。你可以通过和我对话配置一个答疑机器人。下面是一些快捷选项,你可以选择开始配置!', //开场白 + starters: [ + '答疑机器人需要完成哪几步的配置?', + '帮我创建一个 Ant Design 答疑机器人', + ], //预制问题 }; diff --git a/client/app/factory/edit/page.tsx b/client/app/factory/edit/page.tsx index 07db88d1..7259f5b7 100644 --- a/client/app/factory/edit/page.tsx +++ b/client/app/factory/edit/page.tsx @@ -297,7 +297,10 @@ export default function Edit() { onClick={() => { const repoName = extractFullRepoNameFromGitHubUrl(gitUrl); if (repoName) { - onCreateBot(repoName!); + onCreateBot({ + repo_name: repoName!!, + lang: language, + }); } else { toast.error(I18N.edit.page.diZhiYouWu); } diff --git a/client/app/services/BotsController.ts b/client/app/services/BotsController.ts index 34b2e53b..4908337c 100644 --- a/client/app/services/BotsController.ts +++ b/client/app/services/BotsController.ts @@ -39,16 +39,13 @@ export async function deleteBot(id: string) { } // Create Bot -export async function createBot( - repo_name: string, - starters?: string[], - hello_message?: string, -) { - return axios.post(`${apiDomain}/api/bot/create`, { - repo_name, - starters: starters ?? [], - hello_message, - }); +export async function createBot(params: { + repo_name: string; + lang?: string; + starters?: string[]; + hello_message?: string; +}) { + return axios.post(`${apiDomain}/api/bot/create`, params); } // Update Bot diff --git a/server/agent/bot/bot_builder.py b/server/agent/bot/bot_builder.py index 4b8cac1b..0c126577 100644 --- a/server/agent/bot/bot_builder.py +++ b/server/agent/bot/bot_builder.py @@ -13,15 +13,15 @@ def agent_stream_chat( - input_data: ChatData, + input_data: ChatData, user_id: str, bot_id: str, ) -> AsyncIterator[str]: prompt = generate_prompt_by_user_id(user_id, bot_id) agent = AgentBuilder( chat_model=OpenAIClient(), - prompt=prompt, tools=TOOL_MAPPING, enable_tavily=False - ) - return dict_to_sse( - agent.run_stream_chat(input_data) + prompt=prompt, + tools=TOOL_MAPPING, + enable_tavily=False, ) + return dict_to_sse(agent.run_stream_chat(input_data)) diff --git a/server/agent/prompts/bot_builder.py b/server/agent/prompts/bot_builder.py index 5502aeb9..ff4ec528 100644 --- a/server/agent/prompts/bot_builder.py +++ b/server/agent/prompts/bot_builder.py @@ -14,8 +14,8 @@ 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"] +- Generate 3 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", "Review the contribution guidelines", "How can I quickly get started?"] 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. diff --git a/server/bot/router.py b/server/bot/router.py index 11061497..d7c94ce5 100644 --- a/server/bot/router.py +++ b/server/bot/router.py @@ -106,17 +106,23 @@ def get_bot_config( @router.post("/create", status_code=200) async def create_bot( + request: Request, bot_data: BotCreateRequest, user_id: Annotated[str | None, Depends(get_user_id)] = None, ): - blacklist_fields = {"public"} - filtered_bot_data = { - key: value - for key, value in bot_data.model_dump().items() - if key not in blacklist_fields - } + default_starters = [ + 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", 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 + ) + try: - res = await bot_builder(user_id, **filtered_bot_data) + res = await bot_builder(user_id, bot_data.repo_name, starters, hello_message) if not res: return JSONResponse( content={ From 55f4a924c3e15228d6f3ff497525cfa2349a9d09 Mon Sep 17 00:00:00 2001 From: yingying Date: Mon, 18 Nov 2024 15:01:10 +0800 Subject: [PATCH 2/2] chore: fix ci --- server/bot/router.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/bot/router.py b/server/bot/router.py index d7c94ce5..09d99298 100644 --- a/server/bot/router.py +++ b/server/bot/router.py @@ -110,12 +110,13 @@ async def create_bot( bot_data: BotCreateRequest, user_id: Annotated[str | None, Depends(get_user_id)] = None, ): + lang = bot_data.lang or "en" default_starters = [ - 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), + request.state.i18n.get_text("starter0", lang), + request.state.i18n.get_text("starter1", lang), + request.state.i18n.get_text("starter2", lang), ] - default_hello_message = request.state.i18n.get_text("hello_message", bot_data.lang) + default_hello_message = request.state.i18n.get_text("hello_message", 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 @@ -144,12 +145,13 @@ async def bot_generator( bot_data: BotCreateRequest, user_id: Annotated[str | None, Depends(get_user_id)] = None, ): + lang = bot_data.lang or "en" default_starters = [ - 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), + request.state.i18n.get_text("starter0", lang), + request.state.i18n.get_text("starter1", lang), + request.state.i18n.get_text("starter2", lang), ] - default_hello_message = request.state.i18n.get_text("hello_message", bot_data.lang) + default_hello_message = request.state.i18n.get_text("hello_message", 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