Github
Guide to use github tool on your AI agent using Vity Toolkit
Search repositories, manage files, issues, and pull requests programmatically with GitHub’s REST APIs.
Details
Supported Auth Type
AuthType.API_KEYQuick Start
1
Install the package.
npm install vity-toolkit langchain @langchain/openai2
Initialize Vity Toolkit and Langchain.
import { ChatOpenAI } from "@langchain/openai";
import { App, LangchainToolkit } from "vity-toolkit";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
const P = (globalThis as any).process;
const model = new ChatOpenAI({ model: "gpt-4o" });
const toolKit = new LangchainToolkit({
userPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
appPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
});Make sure that you already have integrated and connected the app.
3
Add the tool.
const tools = toolKit.getTools({ apps: [App.GITHUB] });4
Define the Agent.
const prompt = ChatPromptTemplate.fromMessages([
["system", `You are an AI agent responsible for taking actions on GitHub on users' behalf.
You need to take action on GitHub using GitHub APIs. Use correct tools to run APIs from the given tool-set.`],
["placeholder", "{chat_history}"],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);
const agent = createToolCallingAgent({ llm: model, tools, prompt });
const agentExecutor = new AgentExecutor({
agent,
tools,
verbose: false,
});5
Execute the Agent.
const response = await agentExecutor.invoke({ input: "Search for repositories related to 'machine learning python'" });
console.log(response);Supported Actions
Action
Description
Action.GITHUB_SEARCH_REPOSITORIESSearch for GitHub repositories using the GitHub API.
Action.GITHUB_CREATE_REPOSITORYCreate a new GitHub repository in your account.
Action.GITHUB_GET_FILE_CONTENTSGet the contents of a file or directory from a GitHub repository.
Action.GITHUB_CREATE_OR_UPDATE_FILECreate or update a single file in a GitHub repository.
Action.GITHUB_CREATE_ISSUECreate a new issue in a GitHub repository.
Action.GITHUB_CREATE_PULL_REQUESTCreate a new pull request in a GitHub repository.
Last updated