mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
feat: add github tool
This commit is contained in:
parent
84e7e6b859
commit
0ad0e2d237
3 changed files with 66 additions and 2 deletions
|
|
@ -54,6 +54,7 @@ import { QwenApi } from '../utils/alibaba/qwen-api.js'
|
||||||
import { BingAIClient } from '../client/CopilotAIClient.js'
|
import { BingAIClient } from '../client/CopilotAIClient.js'
|
||||||
import Keyv from 'keyv'
|
import Keyv from 'keyv'
|
||||||
import crypto from 'crypto'
|
import crypto from 'crypto'
|
||||||
|
import {GithubAPITool} from '../utils/tools/GithubTool.js'
|
||||||
|
|
||||||
export const roleMap = {
|
export const roleMap = {
|
||||||
owner: 'group owner',
|
owner: 'group owner',
|
||||||
|
|
@ -774,7 +775,8 @@ async function collectTools (e) {
|
||||||
new SendMessageToSpecificGroupOrUserTool(),
|
new SendMessageToSpecificGroupOrUserTool(),
|
||||||
new SendDiceTool(),
|
new SendDiceTool(),
|
||||||
new QueryGenshinTool(),
|
new QueryGenshinTool(),
|
||||||
new SetTitleTool()
|
new SetTitleTool(),
|
||||||
|
new GithubAPITool()
|
||||||
]
|
]
|
||||||
// todo 3.0再重构tool的插拔和管理
|
// todo 3.0再重构tool的插拔和管理
|
||||||
let /** @type{AbstractTool[]} **/ tools = [
|
let /** @type{AbstractTool[]} **/ tools = [
|
||||||
|
|
@ -796,7 +798,8 @@ async function collectTools (e) {
|
||||||
new APTool(),
|
new APTool(),
|
||||||
// new HandleMessageMsgTool(),
|
// new HandleMessageMsgTool(),
|
||||||
serpTool,
|
serpTool,
|
||||||
new QueryUserinfoTool()
|
new QueryUserinfoTool(),
|
||||||
|
new GithubAPITool()
|
||||||
]
|
]
|
||||||
let systemAddition = ''
|
let systemAddition = ''
|
||||||
if (e.isGroup) {
|
if (e.isGroup) {
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,8 @@ const defaultConfig = {
|
||||||
apiMaxToken: 4096,
|
apiMaxToken: 4096,
|
||||||
enableToolPrivateSend: true, // 是否允许智能模式下私聊骚扰其他群友。主人不受影响。
|
enableToolPrivateSend: true, // 是否允许智能模式下私聊骚扰其他群友。主人不受影响。
|
||||||
geminiForceToolKeywords: [],
|
geminiForceToolKeywords: [],
|
||||||
|
githubAPI: 'https://api.github.com',
|
||||||
|
githubAPIKey: '',
|
||||||
version: 'v2.8.4'
|
version: 'v2.8.4'
|
||||||
}
|
}
|
||||||
const _path = process.cwd()
|
const _path = process.cwd()
|
||||||
|
|
|
||||||
59
utils/tools/GithubTool.js
Normal file
59
utils/tools/GithubTool.js
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
import { AbstractTool } from './AbstractTool.js'
|
||||||
|
import { Config } from '../config.js'
|
||||||
|
|
||||||
|
export class GithubAPITool extends AbstractTool {
|
||||||
|
name = 'github'
|
||||||
|
|
||||||
|
parameters = {
|
||||||
|
properties: {
|
||||||
|
q: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'search keyword'
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['repositories', 'issues', 'users', 'code', 'custom'],
|
||||||
|
description: 'search type. If custom is chosen, you must provide full github api url path.'
|
||||||
|
},
|
||||||
|
num: {
|
||||||
|
type: 'number',
|
||||||
|
description: 'search results limit number, default is 5'
|
||||||
|
},
|
||||||
|
fullUrl: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'if type is custom, you need provide this, such as /repos/OWNER/REPO/actions/artifacts?name=NAME&page=2&per_page=1'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
required: ['q', 'type']
|
||||||
|
}
|
||||||
|
|
||||||
|
func = async function (opts) {
|
||||||
|
let { q, type, num = 5, fullUrl = '' } = opts
|
||||||
|
let headers = {
|
||||||
|
'X-From-Library': 'ikechan8370',
|
||||||
|
Accept: 'application/vnd.github+json'
|
||||||
|
}
|
||||||
|
if (Config.githubAPIKey) {
|
||||||
|
headers.Authorization = `Bearer ${Config.githubAPIKey}`
|
||||||
|
}
|
||||||
|
let res
|
||||||
|
if (type !== 'custom') {
|
||||||
|
let serpRes = await fetch(`${Config.githubAPI}/search/${type}?q=${encodeURIComponent(q)}&per_page=${num}`, {
|
||||||
|
headers
|
||||||
|
})
|
||||||
|
serpRes = await serpRes.json()
|
||||||
|
|
||||||
|
res = serpRes.items
|
||||||
|
} else {
|
||||||
|
let serpRes = await fetch(`${Config.githubAPI}${fullUrl}`, {
|
||||||
|
headers
|
||||||
|
})
|
||||||
|
serpRes = await serpRes.json()
|
||||||
|
res = serpRes.items
|
||||||
|
}
|
||||||
|
|
||||||
|
return `the search results are here in json format:\n${JSON.stringify(res)} \n(Notice that these information are only available for you, the user cannot see them, you next answer should consider about the information)`
|
||||||
|
}
|
||||||
|
|
||||||
|
description = 'Useful when you want to search something from api.github.com. You can use preset search types or build your own url path with order, per_page, page and other params.'
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue