FEATURE: Add GitHub Helper AI Bot persona and tools (#513)
Introduces a new AI Bot persona called 'GitHub Helper' which is specialized in assisting with GitHub-related tasks and questions. It includes the following key changes:
- Implements the GitHub Helper persona class with its system prompt and available tools
- Adds three new AI Bot tools for GitHub interactions:
- github_file_content: Retrieves content of files from a GitHub repository
- github_pull_request_diff: Retrieves the diff for a GitHub pull request
- github_search_code: Searches for code in a GitHub repository
- Updates the AI Bot dialects to support the new GitHub tools
- Implements multiple function calls for standard tool dialect
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module DiscourseAi
|
||||
module AiBot
|
||||
module Tools
|
||||
class GithubPullRequestDiff < Tool
|
||||
def self.signature
|
||||
{
|
||||
name: name,
|
||||
description: "Retrieves the diff for a GitHub pull request",
|
||||
parameters: [
|
||||
{
|
||||
name: "repo",
|
||||
description: "The repository name in the format 'owner/repo'",
|
||||
type: "string",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "pull_id",
|
||||
description: "The ID of the pull request",
|
||||
type: "integer",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
}
|
||||
end
|
||||
|
||||
def self.name
|
||||
"github_pull_request_diff"
|
||||
end
|
||||
|
||||
def repo
|
||||
parameters[:repo]
|
||||
end
|
||||
|
||||
def pull_id
|
||||
parameters[:pull_id]
|
||||
end
|
||||
|
||||
def url
|
||||
@url
|
||||
end
|
||||
|
||||
def invoke(_bot_user, llm)
|
||||
api_url = "https://api.github.com/repos/#{repo}/pulls/#{pull_id}"
|
||||
@url = "https://github.com/#{repo}/pull/#{pull_id}"
|
||||
|
||||
response =
|
||||
send_http_request(
|
||||
api_url,
|
||||
headers: {
|
||||
"Accept" => "application/vnd.github.v3.diff",
|
||||
},
|
||||
authenticate_github: true,
|
||||
)
|
||||
|
||||
if response.code == "200"
|
||||
diff = response.body
|
||||
diff = truncate(diff, max_length: 20_000, percent_length: 0.3, llm: llm)
|
||||
{ diff: diff }
|
||||
else
|
||||
{ error: "Failed to retrieve the diff. Status code: #{response.code}" }
|
||||
end
|
||||
end
|
||||
|
||||
def description_args
|
||||
{ repo: repo, pull_id: pull_id, url: url }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user