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

feat: add issue-related tools #53

Merged
merged 1 commit into from
Mar 22, 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"bootstrap": "yarn && bash setup_python.sh",
"fastapi-dev": "cd server && ../venv/bin/python3 -m uvicorn index:app --reload",
"bootstrap": "yarn && cd server && bash setup_python.sh",
"fastapi-dev": "cd server && ./venv/bin/python3 -m uvicorn main:app --reload",
"dev": "next dev",
"dev:python": "concurrently \"yarn run dev\" \"yarn run fastapi-dev\"",
"build": "next build",
Expand Down
5 changes: 4 additions & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ DOCKER_SOCKET_LOCATION=/var/run/docker.sock

# Google Cloud Project details
GOOGLE_PROJECT_ID=GOOGLE_PROJECT_ID
GOOGLE_PROJECT_NUMBER=GOOGLE_PROJECT_NUMBER
GOOGLE_PROJECT_NUMBER=GOOGLE_PROJECT_NUMBER

# GitHub Access Token
GITHUB_TOKEN=GITHUB_TOKEN
7 changes: 5 additions & 2 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
fastapi==0.100.1
uvicorn[standard]==0.23.2
langchain==0.0.352
openai==1.6.0
python-dotenv==1.0.0
langchain
openai
mangum
langsmith
langchain-openai
PyGithub
File renamed without changes.
76 changes: 76 additions & 0 deletions server/tools/issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import json
import os
from github import Github
from langchain.tools import tool

GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')

g = Github(GITHUB_TOKEN)

@tool
def create_issue(repo_name, title, body):
"""
Create an issue in the specified GitHub repository.

:param repo_name: The name of the repository, e.g., "octocat/Hello-World"
:param title: The title of the issue to be created
:param body: The content of the issue to be created
"""
try:
# Get the repository object
repo = g.get_repo(repo_name)
print(f"repo: {repo}")

# Create an issue
issue = repo.create_issue(title=title, body=body)
print(f"issue: {issue}")
return issue.html_url
except Exception as e:
print(f"An error occurred: {e}")
return None

@tool
def get_issues_list(repo_name, state="open"):
"""
Fetches issues from the configured repository

:param repo_name: The name of the repository, e.g., "octocat/Hello-World"
:state: The state of the issue, e.g: open, closed, all
"""
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)

issues_list = [
{
'issue_name': f'Issue #{issue.number} - {issue.title}',
'issue_url': issue.html_url
}
for issue in open_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):
"""
Match issue by the issue number

:param repo_name: The name of the repository, e.g., "octocat/Hello-World"
:number: The number of the issue
"""
try:
# Obtain the repository object
repo = g.get_repo(repo_name)

issues = repo.get_issue(number=number)
print(f"issues: {issues}")
return issues
except Exception as e:
print(f"An error occurred: {e}")
return json.dumps([])
Loading