Skip to content

Commit

Permalink
feat: add tools: search_issues, search_code
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying committed Apr 8, 2024
1 parent 8bd1c8a commit 5da3395
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
5 changes: 2 additions & 3 deletions server/agent/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ def get_datetime() -> datetime:
TOOL_MAPPING = {
"get_datetime": get_datetime,
"create_issue": issue.create_issue,
"get_issues_list": issue.get_issues_list,
"get_issues_by_number": issue.get_issues_by_number
"search_issues": issue.search_issues,
}
TOOLS = ["get_datetime", "create_issue", "get_issues_list", "get_issues_by_number"]
TOOLS = ["get_datetime", "create_issue", "search_issues"]


def _create_agent_with_tools(openai_api_key: str ) -> AgentExecutor:
Expand Down
53 changes: 41 additions & 12 deletions server/tools/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')

DEFAULT_REPOSITORY = "ant-design/ant-design"

g = Github(GITHUB_TOKEN)

@tool
Expand All @@ -30,47 +32,74 @@ def create_issue(repo_name, title, body):
return None

@tool
def get_issues_list(repo_name, state="open"):
def get_issues(
max_num=5,
repo_name=DEFAULT_REPOSITORY,
state="all",
sort="created",
order="desc",
):
"""
Fetches issues from the configured repository
:param max_num: The maximum number of issues to fetch
:param repo_name: The name of the repository, e.g., "octocat/Hello-World"
:state: The state of the issue, e.g: open, closed, all
:param state: The state of the issue, e.g: open, closed, all
:param sort: The sorting method, e.g: created, updated, comments
:param order: The order of the sorting, e.g: asc, desc
"""
try:
# Obtain the repository object
repo = g.get_repo(repo_name)

# Retrieve a list of open issues from the repository
open_issues = repo.get_issues(state=state)
# Retrieve a list of issues from the repository
issues = repo.get_issues(state=state, sort=sort, direction=order)[:max_num]

issues_list = [
{
'issue_name': f'Issue #{issue.number} - {issue.title}',
'issue_url': issue.html_url
}
for issue in open_issues
for issue in issues
]
return json.dumps(issues_list)
except Exception as e:
print(f"An error occurred: {e}")
return json.dumps([])

@tool
def get_issues_by_number(repo_name, number):
def search_issues(
keyword,
repo_name=DEFAULT_REPOSITORY,
max_num=5,
sort="created",
order="desc",
):
"""
Match issue by the issue number
Fetches issues from the configured repository
:param keyword: The keyword to search for in the issues
:param repo_name: The name of the repository, e.g., "octocat/Hello-World"
:number: The number of the issue
:param max_num: The maximum number of issues to fetch
:param sort: The sorting method, e.g: created, updated, comments
:param order: The order of the sorting, e.g: asc, desc
"""
try:
# Obtain the repository object
repo = g.get_repo(repo_name)

issues = repo.get_issue(number=number)
print(f"issues: {issues}")
return issues
search_query = f'repo:{repo_name} {keyword} in:title,body,comments'

# Retrieve a list of open issues from the repository
issues = repo.search_issues(query=search_query, sort=sort, order=order)[:max_num]

issues_list = [
{
'issue_name': f'Issue #{issue.number} - {issue.title}',
'issue_url': issue.html_url
}
for issue in issues
]
return json.dumps(issues_list)
except Exception as e:
print(f"An error occurred: {e}")
return json.dumps([])

0 comments on commit 5da3395

Please sign in to comment.