Skip to content

Commit c46ba0b

Browse files
authored
Merge pull request #106 from ant-xuexiao/feat_chat_create_bot
2 parents 38e100d + 9a4356e commit c46ba0b

File tree

10 files changed

+96
-41
lines changed

10 files changed

+96
-41
lines changed

lui/src/services/ChatController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function streamChat(
88
messages: IPrompt[],
99
host = 'http://127.0.0.1:8000',
1010
): Promise<Response> {
11-
return fetch(`${host}/api/chat/qa`, {
11+
return fetch(`${host}/api/chat/builder`, {
1212
method: 'POST',
1313
headers: {
1414
'Content-Type': 'application/json',

server/agent/bot_builder.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
from typing import AsyncIterator
22
from data_class import ChatData
33
from agent.base import AgentBuilder
4+
from tools import bot_builder
45

56
PROMPT = """
67
# 角色
7-
你是一 GitHub 答疑机器创建助手。你擅长根据用户提供的 Github 仓库信息创建一个答疑机器人。
8+
你是一名 GitHub 答疑机器创建助手。你擅长根据用户提供的 Github 仓库信息创建一个答疑机器人。
89
910
## 技能
10-
### 技能1:获取并确认仓库信息
11-
- 引导用户提供他们的GitHub仓库信息
12-
- 根据提供的信息确认这个仓库存在并且可以访问
11+
### 技能1:获取 GitHub 仓库名
12+
- 引导用户提供他们的 GitHub 仓库名或地址
13+
- 根据提供的 GitHub 地址提取 GitHub 仓库名
1314
1415
### 技能2:创建答疑机器人
15-
- 使用bot_builder工具根据用户提供的Github仓库信息创建机器人
16+
- 使用 bot_builder 工具根据用户提供的 Github 仓库名创建机器人
1617
1718
### 技能3:修改机器人的配置
1819
- 根据用户的描述进行机器人的配置信息修改。
@@ -24,8 +25,10 @@
2425
"""
2526

2627

27-
TOOL_MAPPING = {}
28+
TOOL_MAPPING = {
29+
"bot_builder": bot_builder.create_bot,
30+
}
2831

2932
def agent_chat(input_data: ChatData) -> AsyncIterator[str]:
30-
agent = AgentBuilder(prompt=PROMPT, tools={}, enable_tavily=False)
33+
agent = AgentBuilder(prompt=PROMPT, tools=TOOL_MAPPING, enable_tavily=False)
3134
return agent.run_chat(input_data)

server/agent/qa_chat.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
from typing import AsyncIterator
22
from data_class import ChatData
33
from agent.base import AgentBuilder
4+
from prompts.bot_template import generate_prompt_by_repo_name
45
from tools import issue, sourcecode, knowledge
56

67

7-
PROMPT = """
8-
# Character
9-
You are a skilled assistant dedicated to Ant Design, capable of delivering comprehensive insights and solutions pertaining to Ant Design. You excel in fixing code issues correlated with Ant Design.
10-
11-
## Skills
12-
### Skill 1: Engaging Interaction
13-
Your primary role involves engaging with users, offering them in-depth responses to their Ant Design inquiries in a conversational fashion.
14-
15-
### Skill 2: Insightful Information Search
16-
For queries that touch upon unfamiliar zones, you are equipped with two powerful knowledge lookup tools, used to gather necessary details:
17-
- search_knowledge: This is your initial resource for queries concerning ambiguous topics about Ant Design. While using this, ensure to retain the user's original query language for the highest accuracy possible. Therefore, a specific question like 'Ant Design的新特性是什么?' should be searched as 'Ant Design的新特性是什么?'.
18-
- tavily_search_results_json: Should search_knowledge fail to accommodate the required facts, this tool would be the next step.
19-
20-
### Skill 3: Expert Issue Solver
21-
In case of specific issues reported by users, you are to aid them using a selection of bespoke tools, curated as per the issue nature and prescribed steps. The common instances cater to:
22-
- Routine engagement with the user.
23-
- Employment of certain tools such as create_issue, get_issues, search_issues, search_code etc. when the user is facing a specific hurdle.
24-
25-
## Constraints:
26-
- Maintain a strict focus on Ant Design in your responses; if confronted with unrelated queries, politely notify the user of your confines and steer them towards asking questions relevant to Ant Design.
27-
- Your tool utilization choices should be driven by the nature of the inquiry and recommended actions.
28-
- While operating tools for searching information, keep the user's original language to attain utmost precision.
29-
- With your multilingual capability, always respond in the user's language. If the inquiry popped is in English, your response should mirror that; same goes for Chinese or any other language.
30-
"""
31-
32-
338
TOOL_MAPPING = {
349
"search_knowledge": knowledge.search_knowledge,
3510
"create_issue": issue.create_issue,
@@ -39,5 +14,6 @@
3914
}
4015

4116
def agent_chat(input_data: ChatData) -> AsyncIterator[str]:
42-
agent = AgentBuilder(prompt=PROMPT, tools=TOOL_MAPPING)
43-
return agent.run_chat(input_data)
17+
prompt = generate_prompt_by_repo_name("ant-design")
18+
agent = AgentBuilder(prompt=prompt, tools=TOOL_MAPPING)
19+
return agent.run_chat(input_data)

server/prompts/bot_builder.py

Whitespace-only changes.

server/prompts/bot_generator.py

Whitespace-only changes.

server/prompts/bot_template.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
3+
4+
PROMPT = """
5+
# Character
6+
You are a skilled assistant dedicated to {repo_name}, capable of delivering comprehensive insights and solutions pertaining to {repo_name}. You excel in fixing code issues correlated with {repo_name}.
7+
8+
## Skills
9+
### Skill 1: Engaging Interaction
10+
Your primary role involves engaging with users, offering them in-depth responses to their {repo_name} inquiries in a conversational fashion.
11+
12+
### Skill 2: Insightful Information Search
13+
For queries that touch upon unfamiliar zones, you are equipped with two powerful knowledge lookup tools, used to gather necessary details:
14+
- search_knowledge: This is your initial resource for queries concerning ambiguous topics about {repo_name}. While using this, ensure to retain the user's original query language for the highest accuracy possible. Therefore, a specific question like '{repo_name} 的新特性是什么?' should be searched as '{repo_name} 的新特性是什么?'.
15+
- tavily_search_results_json: Should search_knowledge fail to accommodate the required facts, this tool would be the next step.
16+
17+
### Skill 3: Expert Issue Solver
18+
In case of specific issues reported by users, you are to aid them using a selection of bespoke tools, curated as per the issue nature and prescribed steps. The common instances cater to:
19+
- Routine engagement with the user.
20+
- Employment of certain tools such as create_issue, get_issues, search_issues, search_code etc. when the user is facing a specific hurdle.
21+
22+
## Constraints:
23+
- Maintain a strict focus on {repo_name} in your responses; if confronted with unrelated queries, politely notify the user of your confines and steer them towards asking questions relevant to {repo_name}.
24+
- Your tool utilization choices should be driven by the nature of the inquiry and recommended actions.
25+
- While operating tools for searching information, keep the user's original language to attain utmost precision.
26+
- With your multilingual capability, always respond in the user's language. If the inquiry popped is in English, your response should mirror that; same goes for Chinese or any other language.
27+
"""
28+
29+
def generate_prompt_by_repo_name(repo_name: str):
30+
return PROMPT.format(repo_name=repo_name)

server/tools/bot_builder.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from langchain.tools import tool
2+
from github import Github
3+
from db.supabase.client import get_client
4+
from prompts.bot_template import generate_prompt_by_repo_name
5+
6+
g = Github()
7+
8+
@tool
9+
def create_bot(
10+
repo_name: str,
11+
starters: list[str] = ["介绍一下项目", "快速上手", "贡献指南"],
12+
):
13+
"""
14+
create a bot based on the given github repository.
15+
16+
:param repo_name: The name of the repository, e.g., "octocat/Hello-World"
17+
:param starters: The Opening Dialog, e.g.["介绍一下项目", "快速上手", "贡献指南"]
18+
"""
19+
try:
20+
# Step1:Get the repository object
21+
repo = g.get_repo(repo_name)
22+
23+
# Step2: Generate the prompt
24+
prompt = generate_prompt_by_repo_name(repo_name)
25+
26+
# Step3: Create bot based on the prompt
27+
bot_data = {
28+
"name": repo.name,
29+
"description": repo.description,
30+
"avatar": repo.organization.avatar_url if repo.organization else None,
31+
"prompt": prompt,
32+
"uid": "u123456", # TODO get from auth
33+
"enable_img_generation": False,
34+
"label": "Assistant",
35+
"starters": starters,
36+
"enable_img_generation": False,
37+
"public": False,
38+
}
39+
print('bot_data', bot_data)
40+
supabase = get_client()
41+
response = supabase.table("bots").insert(bot_data).execute()
42+
return response
43+
except Exception as e:
44+
print(f"An error occurred: {e}")
45+
return e
46+

server/tools/issue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def get_issues(
5454

5555
issues_list = [
5656
{
57-
'issue_name': f'Issue #{issue.number} - {issue.title}',
58-
'issue_url': issue.html_url
57+
"issue_name": f"Issue #{issue.number} - {issue.title}",
58+
"issue_url": issue.html_url
5959
}
6060
for issue in issues
6161
]

server/tools/knowledge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@tool
66
def search_knowledge(
7-
query: str,
7+
query: str,
88
):
99
"""
1010
Search for information based on the query. When use this tool, do not translate the search query. Use the original query language to search. eg: When user's question is 'Ant Design 有哪些新特性?', the query should be 'Ant Design 有哪些新特性?'.

server/type_class/bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class BotCreateRequest(BaseModel):
1212
name: Optional[str] = None
1313
starters: Optional[List[str]] = None # 假设为起始文本列表
1414
voice: Optional[str] = None
15-
public: Optional[bool] = None
15+
public: Optional[bool] = False
1616
class BotUpdateRequest(BaseModel):
1717
avatar: Optional[str] = None
1818
description: Optional[str] = None
@@ -23,4 +23,4 @@ class BotUpdateRequest(BaseModel):
2323
name: Optional[str] = None
2424
starters: Optional[List[str]] = None
2525
voice: Optional[str] = None
26-
public: Optional[bool] = None
26+
public: Optional[bool] = None

0 commit comments

Comments
 (0)