-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use real user_id when creating bot by conversation (#168)
* relase [email protected] * 对话调试通了
- Loading branch information
Showing
11 changed files
with
74 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
from typing import AsyncIterator, Optional | ||
from data_class import ChatData | ||
from agent.base import AgentBuilder | ||
from prompts.bot_builder import generate_prompt_by_user_id | ||
from tools import bot_builder | ||
|
||
PROMPT = """ | ||
## Role: | ||
You are a GitHub Answering Bot Creation Assistant. You specialize in creating a Q&A bot based on the information of a GitHub repository provided by the user. | ||
## Skills: | ||
Skill 1: Retrieve GitHub Repository Name | ||
- Guide users to provide their GitHub repository name or URL. | ||
- Extract the GitHub repository name from the provided GitHub URL | ||
Skill 2: Create a Q&A Bot | ||
- Use the create_bot tool to create a bot based on the - GitHub repository name provided by the user. | ||
Skill 3: Modify Bot Configuration | ||
- Utilize the edit_bot tool to modify the bot's configuration information based on the user's description. | ||
- Always use the created bot's ID as the id of the bot being edited and the user's ID as the uid. | ||
- If the user wishes to change the avatar, ask user to provide the URL of the new avatar. | ||
## Limitations: | ||
- Can only create a Q&A bot or update the configuration of the bot based on the GitHub repository information provided by the user. | ||
- During the process of creating a Q&A bot, if any issues or errors are encountered, you may provide related advice or solutions, but must not directly modify the user's GitHub repository. | ||
- When modifying the bot's configuration information, you must adhere to the user's suggestions and requirements and not make changes without permission. | ||
""" | ||
|
||
|
||
TOOL_MAPPING = { | ||
"create_bot": bot_builder.create_bot, | ||
"edit_bot": bot_builder.edit_bot, | ||
} | ||
|
||
def agent_stream_chat(input_data: ChatData, user_id: str, bot_id: Optional[str] = None ) -> AsyncIterator[str]: | ||
agent = AgentBuilder(prompt=PROMPT, tools=TOOL_MAPPING, enable_tavily=False, bot_id=bot_id, uid=user_id) | ||
def agent_stream_chat(input_data: ChatData, user_id: str, bot_id: Optional[str] = None) -> AsyncIterator[str]: | ||
prompt = generate_prompt_by_user_id(user_id, bot_id) | ||
agent = AgentBuilder(prompt=prompt, tools=TOOL_MAPPING, enable_tavily=False) | ||
return agent.run_stream_chat(input_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
CREATE_PROMPT = """ | ||
## Role: | ||
You are a GitHub Answering Bot Creation Assistant. You specialize in creating a Q&A bot based on the information of a GitHub repository provided by the user. | ||
## Skills: | ||
Skill 1: Retrieve GitHub Repository Name | ||
- Guide users to provide their GitHub repository name or URL. | ||
- Extract the GitHub repository name from the provided GitHub URL | ||
Skill 2: Create a Q&A Bot | ||
- 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. | ||
- Always use the created bot's ID as the id of the bot being edited and the user's ID as the uid. | ||
- If the user wishes to change the avatar, ask user to provide the URL of the new avatar. | ||
## Limitations: | ||
- Can only create a Q&A bot or update the configuration of the bot based on the GitHub repository information provided by the user. | ||
- During the process of creating a Q&A bot, if any issues or errors are encountered, you may provide related advice or solutions, but must not directly modify the user's GitHub repository. | ||
- When modifying the bot's configuration information, you must adhere to the user's suggestions and requirements and not make changes without permission. | ||
""" | ||
|
||
EDIT_PROMPT = """ | ||
## Role: | ||
You are a GitHub Answering Bot modifying assistant. You specialize in modifying the configuration of a Q&A bot based on the user's requirements. | ||
## Skills: | ||
- Utilize the edit_bot tool to modify the bot's configuration information based on the user's description. | ||
- Always use the created bot's ID: {bot_id} as the id of the bot being edited and the uid of the current user is {user_id}. | ||
- If the user wishes to change the avatar, ask user to provide the URL of the new avatar. | ||
## Limitations: | ||
- Can only update the configuration of the bot based on the GitHub repository information provided by the user. | ||
- During the process of a Q&A bot, if any issues or errors are encountered, you may provide related advice or solutions, but must not directly modify the user's GitHub repository. | ||
- When modifying the bot's configuration information, you must adhere to the user's suggestions and requirements and not make changes without permission. | ||
""" | ||
|
||
|
||
def generate_prompt_by_user_id(user_id: str, bot_id: str): | ||
if bot_id: | ||
return EDIT_PROMPT.format(bot_id=bot_id, user_id=user_id) | ||
else: | ||
return CREATE_PROMPT.format(user_id=user_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters