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 issue of search_knowledge in chat chain #442

Merged
merged 2 commits into from
Oct 16, 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
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 @@
@property
def id(self):
return self._bot.id

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

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

Check warning on line 33 in server/agent/bot/__init__.py

View check run for this annotation

Codecov / codecov/patch

server/agent/bot/__init__.py#L33

Added line #L33 was not covered by tests

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

Check warning on line 37 in server/agent/bot/__init__.py

View check run for this annotation

Codecov / codecov/patch

server/agent/bot/__init__.py#L37

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

Check warning on line 7 in server/agent/tools/knowledge.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/knowledge.py#L7

Added line #L7 was not covered by tests

@tool(parse_docstring=True)
def search_knowledge(
Expand All @@ -15,6 +16,8 @@
query: The user's question.
"""
try:
bot = get_bot_by_id(bot_id)
repo_name = bot.repo_name if bot.repo_name else ""

Check warning on line 20 in server/agent/tools/knowledge.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/knowledge.py#L19-L20

Added lines #L19 - L20 were not covered by tests
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