mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-15 22:29:24 +03:00
5.4 KiB
5.4 KiB
In [ ]:
%pip install pygithubIn [2]:
import os
from langchain.agents import AgentType
from langchain.agents import initialize_agent
from langchain.agents.agent_toolkits.github.toolkit import GitHubToolkit
from langchain.llms import OpenAI
from langchain.utilities.github import GitHubAPIWrapperIn [3]:
os.environ["GITHUB_APP_ID"] = "your-github-app-id"
os.environ["GITHUB_APP_PRIVATE_KEY"] = "/path/to/your/private/key"
os.environ["GITHUB_REPOSITORY"] = "user/repo"
os.environ["GITHUB_BRANCH"] = "branch-name"
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"In [4]:
llm = OpenAI(temperature=0)
github = GitHubAPIWrapper()
toolkit = GitHubToolkit.from_github_api_wrapper(github)
agent = initialize_agent(
toolkit.get_tools(), llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)In [5]:
agent.run(
"You have the software engineering capabilities of a Google Principle engineer. You are tasked with completing issues on a github repository. Please look at the existing issues and complete them."
)Out [5]:
[1m> Entering new AgentExecutor chain...[0m
[32;1m[1;3m I need to figure out what issues need to be completed and how to complete them.
Action: Get Issues
Action Input: N/A[0m
Observation: [36;1m[1;3mFound 1 issues:
[{'title': 'Change the main script to print Hello AI!', 'number': 1}][0m
Thought:[32;1m[1;3m I need to get more information about this issue.
Action: Get Issue
Action Input: 1[0m
Observation: [33;1m[1;3m{'title': 'Change the main script to print Hello AI!', 'body': None, 'comments': '[]'}[0m
Thought:[32;1m[1;3m I need to update the main script to print Hello AI!
Action: Update File
Action Input: main.py
OLD <<<<
print("Hello World!")
>>>> OLD
NEW <<<<
print("Hello AI!")
>>>> NEW[0m
Observation: [38;5;200m[1;3mFile content was not updated because the old content was not found. It may be helpful to use the read_file action to get the current file contents.[0m
Thought:[32;1m[1;3m I need to read the current file contents.
Action: Read File
Action Input: main.py[0m
Observation: [33;1m[1;3mprint("Hello world!")
[0m
Thought:[32;1m[1;3m I need to update the main script to print Hello AI!
Action: Update File
Action Input: main.py
OLD <<<<
print("Hello world!")
>>>> OLD
NEW <<<<
print("Hello AI!")
>>>> NEW[0m
Observation: [38;5;200m[1;3mUpdated file main.py[0m
Thought:[32;1m[1;3m I now know the final answer
Final Answer: The main script has been updated to print "Hello AI!"[0m
[1m> Finished chain.[0m
'The main script has been updated to print "Hello AI!"'