Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: solve the error in bot creation #482

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!!,
xingwanying marked this conversation as resolved.
Show resolved Hide resolved
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,

Check warning on line 25 in server/agent/bot/bot_builder.py

View check run for this annotation

Codecov / codecov/patch

server/agent/bot/bot_builder.py#L25

Added line #L25 was not covered by tests
)
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 @@

@router.post("/create", status_code=200)
async def create_bot(
request: Request,
xingwanying marked this conversation as resolved.
Show resolved Hide resolved
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"

Check warning on line 113 in server/bot/router.py

View check run for this annotation

Codecov / codecov/patch

server/bot/router.py#L113

Added line #L113 was not covered by tests
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 = (

Check warning on line 121 in server/bot/router.py

View check run for this annotation

Codecov / codecov/patch

server/bot/router.py#L118-L121

Added lines #L118 - L121 were not covered by tests
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 @@
bot_data: BotCreateRequest,
user_id: Annotated[str | None, Depends(get_user_id)] = None,
):
lang = bot_data.lang or "en"

Check warning on line 148 in server/bot/router.py

View check run for this annotation

Codecov / codecov/patch

server/bot/router.py#L148

Added line #L148 was not covered by tests
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),

Check warning on line 152 in server/bot/router.py

View check run for this annotation

Codecov / codecov/patch

server/bot/router.py#L151-L152

Added lines #L151 - L152 were not covered by tests
]
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