Skip to content

Commit

Permalink
fix: solve the error in bot creation (#482)
Browse files Browse the repository at this point in the history
* fix: solve the create bot

* chore: fix ci
  • Loading branch information
xingwanying authored Nov 18, 2024
1 parent 3e7db08 commit 40a41c2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 35 deletions.
4 changes: 0 additions & 4 deletions assistant/src/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ const Chat: FC<ChatProps> = memo(
content={
<div className="leftMessageContent">
<div className="ant-pro-chat-list-item-message-content">
<div className="text-left text-[20px] font-[500] leading-[28px] font-sf">
👋🏻 你好,我是{' '}
{botInfo.assistantMeta?.title || BOT_INFO.name}
</div>
<div className="text-left text-[14px] font-[500] leading-[28px] font-sf">
{props.message}
</div>
Expand Down
8 changes: 6 additions & 2 deletions assistant/src/mock/bot.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 答疑机器人',
], //预制问题
};
5 changes: 4 additions & 1 deletion client/app/factory/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 7 additions & 10 deletions client/app/services/BotsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions server/agent/bot/bot_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 2 additions & 2 deletions server/agent/prompts/bot_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 19 additions & 11 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,24 @@ 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
}
lang = bot_data.lang or "en"
default_starters = [
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", 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={
Expand All @@ -138,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
Expand Down

0 comments on commit 40a41c2

Please sign in to comment.