Replies: 8 comments 8 replies
-
Hello, @SAIL-Fang! To create a custom Agent that reviews git commits and checks their names using LangChain, you can follow these steps:
Here's a step-by-step guide with code snippets: Step 1: Define the ToolsFirst, create a tool that can fetch commit names from a git repository. You can use the import subprocess
from langchain.tools import BaseTool
class GitCommitTool(BaseTool):
def invoke(self, input):
result = subprocess.run(["git", "log", "--pretty=format:%s"], capture_output=True, text=True)
return result.stdout.split('\n')
git_commit_tool = GitCommitTool() Step 2: Create the AgentNext, create an agent that uses this tool to review commit names. You can use a language model like GPT-4 for this purpose. from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent
from langchain import hub
# Initialize the language model
model = ChatOpenAI(model="gpt-4")
# Define the prompt for the agent
prompt = hub.pull("hwchase17/openai-functions-agent")
# Create the agent with the model, tools, and prompt
tools = [git_commit_tool]
agent = create_tool_calling_agent(model, tools, prompt) Step 3: Run the AgentFinally, run the agent to review the git commits. from langchain.agents import AgentExecutor
# Combine the agent with the tools inside the AgentExecutor
agent_executor = AgentExecutor(agent=agent, tools=tools)
# Run the agent to review git commits
response = agent_executor.invoke({"input": "Review the git commit names"})
print(response) This setup will allow the agent to fetch git commit names and review them using the language model. Alternative: Using GitLab ToolkitIf you are working with a GitLab repository, you can use the Setup
%pip install --upgrade --quiet python-gitlab langchain-community
Follow the instructions here to create a GitLab personal access token with the necessary permissions.
Set the following environmental variables: import os
os.environ["GITLAB_URL"] = "https://gitlab.example.org"
os.environ["GITLAB_PERSONAL_ACCESS_TOKEN"] = "your_personal_access_token"
os.environ["GITLAB_REPOSITORY"] = "username/repo-name"
os.environ["GITLAB_BRANCH"] = "bot-branch-name"
os.environ["GITLAB_BASE_BRANCH"] = "main"
os.environ["OPENAI_API_KEY"] = "your_openai_api_key" Example: Simple Agentfrom langchain.agents import AgentType, initialize_agent
from langchain_community.agent_toolkits.gitlab.toolkit import GitLabToolkit
from langchain_community.utilities.gitlab import GitLabAPIWrapper
from langchain_openai import OpenAI
llm = OpenAI(temperature=0)
gitlab = GitLabAPIWrapper()
toolkit = GitLabToolkit.from_gitlab_api_wrapper(gitlab)
agent = initialize_agent(
toolkit.get_tools(), llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
agent.run(
"You have the software engineering capabilities of a Google Principle engineer. You are tasked with completing issues on a gitlab repository. Please look at the open issues and complete them by creating merge requests that solve the issues."
) This example demonstrates how to set up an agent that can interact with a GitLab repository, fetch commit names, and perform other repository-related tasks [1][2]. |
Beta Was this translation helpful? Give feedback.
-
@dosu |
Beta Was this translation helpful? Give feedback.
-
@dosu |
Beta Was this translation helpful? Give feedback.
-
@dosu |
Beta Was this translation helpful? Give feedback.
-
@dosu |
Beta Was this translation helpful? Give feedback.
-
@dosu |
Beta Was this translation helpful? Give feedback.
-
@dosu |
Beta Was this translation helpful? Give feedback.
-
@dosu |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I want to create a proxy that can review git commits (i.e. check their names), I have a code naming conventions, git diff section. How should I adjust the template to make the agent work better? I checked the documentation but couldn't find a hint on how to fine-tune the agent.
System Info
$ pip freeze |grep langchain
composio_langchain==0.5.8
langchain==0.2.14
langchain-anthropic==0.1.23
langchain-astradb==0.3.3
langchain-aws==0.1.16
langchain-chroma==0.1.2
langchain-cli==0.0.26
langchain-cohere==0.1.9
langchain-community==0.2.12
langchain-core==0.2.35
langchain-experimental==0.0.61
langchain-google-calendar-tools==0.0.1
langchain-google-community==1.0.7
langchain-google-genai==1.0.8
langchain-google-vertexai==1.0.7
langchain-groq==0.1.6
langchain-huggingface==0.0.3
langchain-milvus==0.1.4
langchain-mistralai==0.1.10
langchain-mongodb==0.1.8
langchain-nvidia-ai-endpoints==0.1.6
langchain-openai==0.1.22
langchain-pinecone==0.1.2
langchain-text-splitters==0.2.2
langchainhub==0.1.21
windows
Beta Was this translation helpful? Give feedback.
All reactions