Skip to content

Commit

Permalink
fix: solve the issue of search_knowledge in chat chain (#442)
Browse files Browse the repository at this point in the history
* fix: solve the issue of search_knowledge in chat chain

* chore: update the denpendence
  • Loading branch information
xingwanying authored Oct 16, 2024
1 parent 0f08935 commit afa6f6f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions petercat_utils/data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ChatData(BaseModel):
llm: Optional[str] = "openai"
prompt: Optional[str] = None
bot_id: Optional[str] = None
repo_name: Optional[str] = None


class ExecuteMessage(BaseModel):
Expand Down
10 changes: 7 additions & 3 deletions server/agent/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from agent.llm import LLM, LLMTokenLike



class Bot:
_bot: BotModel
_llm: LLM
_llm_token: LLMTokenLike

def __init__(self, bot: BotModel, llm_token: LLMTokenLike):
self._bot = bot
self._llm_token = llm_token
Expand All @@ -15,7 +15,7 @@ def __init__(self, bot: BotModel, llm_token: LLMTokenLike):
@property
def id(self):
return self._bot.id

@property
def prompt(self):
return self._bot.prompt
Expand All @@ -30,4 +30,8 @@ def llm(self):

@property
def token_id(self):
return self._bot.token_id
return self._bot.token_id

@property
def repo_name(self):
return self._bot.repo_name
2 changes: 1 addition & 1 deletion server/agent/qa_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_tools(bot: Bot, auth_token: Optional[Auth.Token]):

return {
"check_login": login_tools["check_login"],
"search_knowledge": knowledge.factory(repo_name=bot.repo_name),
"search_knowledge": knowledge.factory(bot_id=bot.id),
"create_issue": issue_tools["create_issue"],
"get_issues": issue_tools["get_issues"],
"get_file_content": pull_request_tools["get_file_content"],
Expand Down
7 changes: 5 additions & 2 deletions server/agent/tools/knowledge.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from agent.bot.get_bot import get_bot_by_id
from langchain.tools import tool
from petercat_utils import retrieval


def factory(repo_name: str):
repo_name = repo_name
def factory(bot_id: str):
bot_id = bot_id

@tool(parse_docstring=True)
def search_knowledge(
Expand All @@ -15,6 +16,8 @@ def search_knowledge(
query: The user's question.
"""
try:
bot = get_bot_by_id(bot_id)
repo_name = bot.repo_name if bot.repo_name else ""
return retrieval.search_knowledge(query, repo_name)
except Exception as e:
print(f"An error occurred: {e}")
Expand Down
2 changes: 1 addition & 1 deletion server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_bot_detail(
data = (
supabase.table("bots")
.select(
"id, created_at, updated_at, avatar, description, name, starters, public, hello_message"
"id, created_at, updated_at, avatar, description, name, starters, public, hello_message, repo_name"
)
.eq("id", id)
.execute()
Expand Down
2 changes: 1 addition & 1 deletion server/core/models/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class BotModel(BaseModel):
id: str
uid: str
repo_name: str
avatar: Optional[str] = ""
description: Optional[str]
prompt: Optional[str] = ""
Expand All @@ -15,7 +16,6 @@ class BotModel(BaseModel):
token_id: Optional[str] = ""
created_at: datetime = datetime.now()
domain_whitelist: Optional[list[str]] = []
repo_name: str = ""


class RepoBindBotConfigVO(BaseModel):
Expand Down
1 change: 0 additions & 1 deletion server/github_app/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ async def github_app_webhook(

if "installation" not in payload:
return {"success": False, "message": "Invalid Webhook request"}
print(f"payload: {payload}")
installation_id = payload["installation"]["id"]
try:
auth = Auth.AppAuth(
Expand Down
2 changes: 1 addition & 1 deletion subscriber/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
petercat_utils>=0.1.36
petercat_utils>=0.1.39

0 comments on commit afa6f6f

Please sign in to comment.