-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
64 lines (52 loc) · 1.87 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from dotenv import load_dotenv
from langchain.tools import StructuredTool
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from langchain.utilities import SerpAPIWrapper
from github_agent.tools.github_tool import GithubTools
load_dotenv()
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY", "")
GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN")
SERPAPI_API_KEY = os.environ.get("SERPAPI_API_KEY")
if not OPENAI_API_KEY or not GITHUB_TOKEN:
raise ValueError("OPENAI_API_KEY and GITHUB_TOKEN must be set in .env file")
github_functions = GithubTools(token=GITHUB_TOKEN)
tools = [
StructuredTool.from_function(
github_functions.search_repositories, name="Search for repositories"
),
StructuredTool.from_function(
github_functions.get_repository_pull_requests, name="Get repository pull requests"
),
StructuredTool.from_function(
github_functions.get_repository_pull_request_information,
name="Get repository pull request information",
),
StructuredTool.from_function(
github_functions.get_repository_issues, name="Get repository issues"
),
StructuredTool.from_function(
github_functions.get_repository_issue_information, name="Get repository issue information"
),
StructuredTool.from_function(
github_functions.comment_in_repository_issue, name="Comment in repository issue"
),
]
if SERPAPI_API_KEY:
tools += [
StructuredTool.from_function(SerpAPIWrapper().run, name="search"),
]
llm = ChatOpenAI(
openai_api_key=OPENAI_API_KEY,
temperature=0,
streaming=True,
verbose=True,
model="gpt-3.5-turbo",
)
agent = initialize_agent(
tools, llm, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
if __name__ == "__main__":
query = input("Enter query: ")
agent.run(query)