Skip to content

Commit

Permalink
fix: bot builder (#335)
Browse files Browse the repository at this point in the history
- 修 bot builder
  • Loading branch information
RaoHai authored Sep 4, 2024
2 parents 00b1cf6 + ad2f8f0 commit 6fcf2ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 4 additions & 5 deletions server/agent/bot/bot_builder.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import AsyncIterator
from agent.bot.get_bot import Bot
from agent.llm.openai import OpenAIClient
from petercat_utils.data_class import ChatData

from agent.base import AgentBuilder
from agent.prompts.bot_builder import generate_prompt_by_user_id
from agent.tools import bot_builder


TOOL_MAPPING = {
"create_bot": bot_builder.create_bot,
"edit_bot": bot_builder.edit_bot,
Expand All @@ -16,11 +15,11 @@
def agent_stream_chat(
input_data: ChatData,
user_id: str,
bot: Bot,
bot_id: str,
) -> AsyncIterator[str]:
prompt = generate_prompt_by_user_id(user_id, bot.id)
prompt = generate_prompt_by_user_id(user_id, bot_id)
agent = AgentBuilder(
chat_model=bot.llm,
chat_model=OpenAIClient(),
prompt=prompt, tools=TOOL_MAPPING, enable_tavily=False
)
return agent.run_stream_chat(input_data)
5 changes: 4 additions & 1 deletion server/agent/prompts/bot_builder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Optional


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.
Expand Down Expand Up @@ -45,7 +48,7 @@
"""


def generate_prompt_by_user_id(user_id: str, bot_id: str):
def generate_prompt_by_user_id(user_id: str, bot_id: Optional[str]):
if bot_id:
return EDIT_PROMPT.format(bot_id=bot_id, user_id=user_id)
else:
Expand Down

0 comments on commit 6fcf2ed

Please sign in to comment.