Open jianghao0718 opened 3 months ago
Sure! Implementing an IssueOps command to read comments from an issue or PR and reply using an LLM (Large Language Model) like ActionAgents involves a series of steps. Below is a guide to help you get started:
gh
for CLI operations.npm install @octokit/rest openai
gh auth login
and follow the prompts to authenticate.GitHub Token:
Register a GitHub App:
issues
, pull_requests
, etc.).const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
});
async function getComments(owner, repo, number) {
const { data } = await octokit.issues.listComments({
owner,
repo,
issue_number: number
});
return data;
}
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY
});
const openai = new OpenAIApi(configuration);
async function generateReply(prompt) {
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: prompt,
max_tokens: 150
});
return completion.data.choices[0].text.trim();
}
async function handleIssueComment(owner, repo, issueNumber) {
try {
const comments = await getComments(owner, repo, issueNumber);
const latestComment = comments[comments.length - 1].body;
const reply = await generateReply(latestComment);
await octokit.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: reply
});
console.log("Reply posted successfully!");
} catch (error) {
console.error("Error handling issue comment:", error);
}
}
handleIssueComment("your-username", "your-repo", 1);
.github/workflows/issue-ops.yml
.name: IssueOps with LLM
on:
issue_comment:
types: [created]
jobs:
reply_with_llm:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install Dependencies
run: npm install
- name: Run IssueOps Command
run: node your-script-file.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Good luck with your implementation! If you have any more questions or need further assistance, feel free to ask! 😊
Get implementation steps for Issue Ops command like
/ai
to read comments of an issue or PR and reply with similar functionality of ActionAgents to answer with LLM.