-
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.
feat: enabel to create bot by text description
- Loading branch information
1 parent
38e100d
commit 9a4356e
Showing
10 changed files
with
96 additions
and
41 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
Empty file.
Empty file.
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,30 @@ | ||
|
||
|
||
|
||
PROMPT = """ | ||
# Character | ||
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}. | ||
## Skills | ||
### Skill 1: Engaging Interaction | ||
Your primary role involves engaging with users, offering them in-depth responses to their {repo_name} inquiries in a conversational fashion. | ||
### Skill 2: Insightful Information Search | ||
For queries that touch upon unfamiliar zones, you are equipped with two powerful knowledge lookup tools, used to gather necessary details: | ||
- 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} 的新特性是什么?'. | ||
- tavily_search_results_json: Should search_knowledge fail to accommodate the required facts, this tool would be the next step. | ||
### Skill 3: Expert Issue Solver | ||
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: | ||
- Routine engagement with the user. | ||
- Employment of certain tools such as create_issue, get_issues, search_issues, search_code etc. when the user is facing a specific hurdle. | ||
## Constraints: | ||
- 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}. | ||
- Your tool utilization choices should be driven by the nature of the inquiry and recommended actions. | ||
- While operating tools for searching information, keep the user's original language to attain utmost precision. | ||
- 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. | ||
""" | ||
|
||
def generate_prompt_by_repo_name(repo_name: str): | ||
return PROMPT.format(repo_name=repo_name) |
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,46 @@ | ||
from langchain.tools import tool | ||
from github import Github | ||
from db.supabase.client import get_client | ||
from prompts.bot_template import generate_prompt_by_repo_name | ||
|
||
g = Github() | ||
|
||
@tool | ||
def create_bot( | ||
repo_name: str, | ||
starters: list[str] = ["介绍一下项目", "快速上手", "贡献指南"], | ||
): | ||
""" | ||
create a bot based on the given github repository. | ||
:param repo_name: The name of the repository, e.g., "octocat/Hello-World" | ||
:param starters: The Opening Dialog, e.g.["介绍一下项目", "快速上手", "贡献指南"] | ||
""" | ||
try: | ||
# Step1:Get the repository object | ||
repo = g.get_repo(repo_name) | ||
|
||
# Step2: Generate the prompt | ||
prompt = generate_prompt_by_repo_name(repo_name) | ||
|
||
# Step3: Create bot based on the prompt | ||
bot_data = { | ||
"name": repo.name, | ||
"description": repo.description, | ||
"avatar": repo.organization.avatar_url if repo.organization else None, | ||
"prompt": prompt, | ||
"uid": "u123456", # TODO get from auth | ||
"enable_img_generation": False, | ||
"label": "Assistant", | ||
"starters": starters, | ||
"enable_img_generation": False, | ||
"public": False, | ||
} | ||
print('bot_data', bot_data) | ||
supabase = get_client() | ||
response = supabase.table("bots").insert(bot_data).execute() | ||
return response | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
return e | ||
|
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