Skip to content

Commit

Permalink
set available tools
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Oct 25, 2024
1 parent 68fdc5e commit 7665a39
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
openai_model: ${{ vars.OPENAI_MODEL }}
system_prompt: ${{ vars.SYSTEM_PROMPT }}
available_tools: ${{ vars.AVAILABLE_TOOLS }}
user_input: |
Please review this issue:
Title: "${{ github.event.issue.title }}"
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

> A universal assistant to help handle GitHub matters
## Features
## Available Tools

- [x] Close issues
- [x] Lock issues
- [x] Comment issues
- [x] Close issue(closeIssue)
- [x] Lock issue(lockIssue)
- [x] Comment issues(commentIssue)
- [ ] and more...

## Usage

Expand All @@ -24,12 +25,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Review Issues
uses: mihomo-party-org/universal-assistant@v1
uses: mihomo-party-org/universal-assistant@v1.0.1
with:
# default is https://api.openai.com/v1
openai_base_url: ${{ secrets.OPENAI_BASE_URL }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
# default is gpt-4o-mini
openai_model: ${{ vars.OPENAI_MODEL }}
system_prompt: ${{ vars.SYSTEM_PROMPT }}
# default is "closeIssue,lockIssue,commentIssue"
available_tools: ${{ vars.AVAILABLE_TOOLS }}
user_input: |
Please review this issue:
Title: "${{ github.event.issue.title }}"
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
user_input:
description: "User Input for the assistant"
required: true
available_tools:
description: "Available tools for the assistant, separated by comma"
required: false
default: "closeIssue,lockIssue,commentIssue"
github_token:
description: "GitHub Token"
required: true
Expand Down
26 changes: 21 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40024,7 +40024,7 @@ const github = __importStar(__nccwpck_require__(3802));
const _1 = __nccwpck_require__(3300);
// close issue
const CloseParams = zod_1.z.object({
reason: zod_1.z.enum(["not_planned", "completed", "reopened"]),
reason: zod_1.z.enum(["not_planned", "completed"]),
});
exports.closeIssue = zodFunction({
name: "closeIssue",
Expand Down Expand Up @@ -40132,7 +40132,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.action_event = exports.github_token = exports.user_input = exports.system_prompt = exports.openai_model = exports.openai_api_key = exports.openai_base_url = void 0;
exports.action_event = exports.available_tools = exports.github_token = exports.user_input = exports.system_prompt = exports.openai_model = exports.openai_api_key = exports.openai_base_url = void 0;
const github_calls_1 = __nccwpck_require__(331);
const github = __importStar(__nccwpck_require__(3802));
const core = __importStar(__nccwpck_require__(4708));
Expand All @@ -40157,10 +40157,25 @@ function checkInput() {
if (!exports.github_token) {
throw new Error("github_token is required");
}
if (github.context.eventName.includes("issue")) {
tools.push(github_calls_1.closeIssue, github_calls_1.lockIssue, github_calls_1.commentIssue);
if (!exports.available_tools) {
exports.available_tools = "closeIssue,lockIssue,commentIssue";
}
// todo: add more tools for other events
exports.available_tools.split(",").forEach((tool) => {
switch (tool) {
case "closeIssue":
tools.push(github_calls_1.closeIssue);
break;
case "lockIssue":
tools.push(github_calls_1.lockIssue);
break;
case "commentIssue":
tools.push(github_calls_1.commentIssue);
break;
default:
throw new Error(`Tool "${tool}" is not available`);
// todo: support more tools
}
});
}
async function main() {
exports.openai_base_url = core.getInput("openai_base_url");
Expand All @@ -40169,6 +40184,7 @@ async function main() {
exports.system_prompt = core.getInput("system_prompt");
exports.user_input = core.getInput("user_input");
exports.github_token = core.getInput("github_token");
exports.available_tools = core.getInput("available_tools");
exports.action_event = github.context.eventName;
checkInput();
const openai = new openai_1.default({
Expand Down
2 changes: 1 addition & 1 deletion src/github_calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { github_token } from ".";

// close issue
const CloseParams = z.object({
reason: z.enum(["not_planned", "completed", "reopened"]),
reason: z.enum(["not_planned", "completed"]),
});
type CloseParams = z.infer<typeof CloseParams>;
export const closeIssue = zodFunction({
Expand Down
23 changes: 20 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export let openai_model: string;
export let system_prompt: string;
export let user_input: string;
export let github_token: string;
export let available_tools: string;
export let action_event: string;
let tools: RunnableToolFunctionWithParse<any>[] = [];

Expand All @@ -32,10 +33,25 @@ function checkInput() {
if (!github_token) {
throw new Error("github_token is required");
}
if (github.context.eventName.includes("issue")) {
tools.push(closeIssue, lockIssue, commentIssue);
if (!available_tools) {
available_tools = "closeIssue,lockIssue,commentIssue";
}
// todo: add more tools for other events
available_tools.split(",").forEach((tool) => {
switch (tool) {
case "closeIssue":
tools.push(closeIssue);
break;
case "lockIssue":
tools.push(lockIssue);
break;
case "commentIssue":
tools.push(commentIssue);
break;
default:
throw new Error(`Tool "${tool}" is not available`);
// todo: support more tools
}
});
}

async function main() {
Expand All @@ -45,6 +61,7 @@ async function main() {
system_prompt = core.getInput("system_prompt");
user_input = core.getInput("user_input");
github_token = core.getInput("github_token");
available_tools = core.getInput("available_tools");
action_event = github.context.eventName;
checkInput();
const openai = new OpenAI({
Expand Down

0 comments on commit 7665a39

Please sign in to comment.