From 45ff6235161c6ea6da043c907aa4d21f8d5c79e1 Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:08:03 +0100 Subject: [PATCH 01/10] feat: prompt basic inference request Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- README.md | 4 ++-- action.yml | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 action.yml diff --git a/README.md b/README.md index a1b9589..7f5b3a8 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # Inference Request via GitHub Action > [!TIP] -> Run an inference request to GitHub Models via GitHub Action. +> Run [inference requests](https://docs.github.com/en/rest/models/inference#run-an-inference-request "GitHub API documentation.") to [GitHub Models](https://github.com/marketplace?type=models "GitHub models catalog.") with this GitHub Action.
@@ -43,4 +43,4 @@ View [all notable changes](https://github.com/op5dev/inference-request/releases - This project is licensed under the **permissive** [Apache License 2.0](LICENSE "Apache License 2.0."). - All works herein are my own, shared of my own volition, and [contributors](https://github.com/op5dev/inference-request/graphs/contributors "Contributors."). -- Copyright 2016-present [Rishav Dhar](https://github.com/rdhar "Rishav Dhar's GitHub profile.") — All wrongs reserved. +- Copyright 2016-present [Rishav Dhar](https://rdhar.dev "Rishav Dhar's profile.") — All wrongs reserved. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..978c2f9 --- /dev/null +++ b/action.yml @@ -0,0 +1,64 @@ +--- +name: Inference Request via GitHub Action +author: Rishav Dhar (https://rdhar.dev) +description: Run inference requests to GitHub Models with this GitHub Action. + +inputs: + github-api-version: + default: "2022-11-28" + description: "GitHub API version (e.g., `2022-11-28`)." + required: false + github-token: + default: ${{ github.token }} + description: "GitHub token (e.g., `secrets.GITHUB_TOKEN`)." + required: false + messages: + default: "[]" + description: 'Messages to send to the model in JSON format (e.g., `[{"role": "user", "content": "Hello!"}]`).' + required: true + model: + default: "openai/o4-mini" + description: "Model to use for inference (e.g., `openai/o4-mini`)." + required: true + org: + default: "" + description: "Organization to which the request should be attributed (e.g., `op5dev`)." + required: false + +runs: + using: composite + steps: + - id: request + shell: bash + env: + API_VERSION: ${{ inputs.github-api-version }} + GH_HOST: ${{ github.server_url }} + GH_TOKEN: ${{ inputs.github-token }} + ORG: ${{ inputs.org != '' && format('orgs/{0}/', inputs.org) || '' }} + run: | + GH_HOST=$(echo $GH_HOST | sed 's/.*:\/\///') + + response_raw=$(curl --request POST --location https://models.github.ai/${ORG}inference/chat/completions \ + --header "Accept: application/vnd.github+json" \ + --header "Authorization: Bearer $GH_TOKEN" \ + --header "Content-Type: application/json" \ + --header "X-GitHub-Api-Version: $API_VERSION" \ + --data '{ + "messages": '"${{ inputs.messages }}"', + "model": '"${{ inputs.model }}"' + }') + + echo "response_raw=$response_raw" >> $GITHUB_OUTPUT + echo "response=$response_raw | jq --raw-output '.choices[0].message.content'" >> $GITHUB_OUTPUT + +outputs: + response: + description: "Placeholder." + value: ${{ steps.request.outputs.response }} + response-raw: + description: "Placeholder." + value: ${{ steps.request.outputs.response_raw }} + +branding: + color: white + icon: loader From 96e1f8e37df75c150c27e3c7ceefada5e4598475 Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:08:09 +0100 Subject: [PATCH 02/10] comment Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5755c5c..6b2aa52 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: runs-on: [ubuntu-24.04] permissions: - contents: write # Required to checkout repository. + contents: write # Required to create tags. id-token: write # Required for authentication. packages: write # Required to publish packages. From 25428cce3d9e3a366e02ebe1e170380d00863f66 Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:08:24 +0100 Subject: [PATCH 03/10] add codeowners Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- .github/CODEOWNERS | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..2479ace --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +# Each line is a file pattern followed by one or more owners. +# Order is important as the last matching pair takes precedence. + +* @rdhar @rdhar-tc From 1ee057de61ad9adfb65141ec875407e533857177 Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:08:34 +0100 Subject: [PATCH 04/10] add ci workflow Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7b0c471 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +--- +name: CI + +on: + pull_request: + paths: [action.yml, .github/workflows/ci.yml] + +jobs: + CI: + runs-on: [ubuntu-24.04] + + permissions: + contents: read # Required to checkout repository. + models: read # Required for model inference. + + steps: + - name: Echo context + env: + GH_JSON: ${{ toJson(github) }} + run: echo "$GH_JSON" + + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + + - name: Inference request + id: prompt + uses: ./ + with: + messages: '[{"role": "user", "content": "Hello!"}]' + model: "openai/o4-mini" + + - name: Echo outputs + continue-on-error: true + run: | + echo "response: ${{ steps.prompt.outputs.response }}" + echo "response-raw: ${{ steps.prompt.outputs.response-raw }}" From f449d05938a931d0d791cb340f0842a406b6479e Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:14:09 +0100 Subject: [PATCH 05/10] hard-code input Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- action.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 978c2f9..e41f315 100644 --- a/action.yml +++ b/action.yml @@ -32,11 +32,10 @@ runs: shell: bash env: API_VERSION: ${{ inputs.github-api-version }} - GH_HOST: ${{ github.server_url }} GH_TOKEN: ${{ inputs.github-token }} ORG: ${{ inputs.org != '' && format('orgs/{0}/', inputs.org) || '' }} run: | - GH_HOST=$(echo $GH_HOST | sed 's/.*:\/\///') + GH_HOST=$(echo $GITHUB_SERVER_URL | sed 's/.*:\/\///') response_raw=$(curl --request POST --location https://models.github.ai/${ORG}inference/chat/completions \ --header "Accept: application/vnd.github+json" \ @@ -44,10 +43,13 @@ runs: --header "Content-Type: application/json" \ --header "X-GitHub-Api-Version: $API_VERSION" \ --data '{ - "messages": '"${{ inputs.messages }}"', - "model": '"${{ inputs.model }}"' - }') + "messages": '[{"role": "user", "content": "Hello!"}]', + "model": "${{ inputs.model }}" + }') + # "messages": '"${{ inputs.messages }}"', + # "model": '"${{ inputs.model }}"' + echo $response_raw echo "response_raw=$response_raw" >> $GITHUB_OUTPUT echo "response=$response_raw | jq --raw-output '.choices[0].message.content'" >> $GITHUB_OUTPUT From 3c4f36b97bb64f4330f858c830a50dadc89d10c3 Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:25:52 +0100 Subject: [PATCH 06/10] reformat Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index e41f315..858d88d 100644 --- a/action.yml +++ b/action.yml @@ -43,9 +43,10 @@ runs: --header "Content-Type: application/json" \ --header "X-GitHub-Api-Version: $API_VERSION" \ --data '{ - "messages": '[{"role": "user", "content": "Hello!"}]', + "messages": [{"role": "user", "content": "What is the capital of France?"}], "model": "${{ inputs.model }}" - }') + }' + ) # "messages": '"${{ inputs.messages }}"', # "model": '"${{ inputs.model }}"' From 6be1a145d702d39777f24f5e26c0e1791ae68d2e Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:28:12 +0100 Subject: [PATCH 07/10] sparse checkout Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b0c471..07d8b2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false + sparse-checkout: action.yml - name: Inference request id: prompt From 7de6e556006a07fe28f3cd2a1880c46e069964d0 Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 21:01:30 +0100 Subject: [PATCH 08/10] include org Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07d8b2e..5837462 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,8 +29,9 @@ jobs: id: prompt uses: ./ with: - messages: '[{"role": "user", "content": "Hello!"}]' - model: "openai/o4-mini" + messages: '[{"role": "user", "content": "What is the capital of France?"}]' + model: openai/o4-mini + org: op5dev - name: Echo outputs continue-on-error: true From c8d8bb248a7bacc986211bb606f69efce9967646 Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 21:39:23 +0100 Subject: [PATCH 09/10] rename project with "ai" prefix Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- README.md | 22 +++++++++++----------- SECURITY.md | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7f5b3a8..ebdbb6d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -[![GitHub license](https://img.shields.io/github/license/op5dev/inference-request?logo=apache&label=License)](LICENSE "Apache License 2.0.") -[![GitHub release tag](https://img.shields.io/github/v/release/op5dev/inference-request?logo=semanticrelease&label=Release)](https://github.com/op5dev/inference-request/releases "View all releases.") +[![GitHub license](https://img.shields.io/github/license/op5dev/ai-inference-request?logo=apache&label=License)](LICENSE "Apache License 2.0.") +[![GitHub release tag](https://img.shields.io/github/v/release/op5dev/ai-inference-request?logo=semanticrelease&label=Release)](https://github.com/op5dev/ai-inference-request/releases "View all releases.") * -[![GitHub repository stargazers](https://img.shields.io/github/stars/op5dev/inference-request)](https://github.com/op5dev/inference-request "Become a stargazer.") +[![GitHub repository stargazers](https://img.shields.io/github/stars/op5dev/ai-inference-request)](https://github.com/op5dev/ai-inference-request "Become a stargazer.") -# Inference Request via GitHub Action +# AI Inference Request via GitHub Action > [!TIP] -> Run [inference requests](https://docs.github.com/en/rest/models/inference#run-an-inference-request "GitHub API documentation.") to [GitHub Models](https://github.com/marketplace?type=models "GitHub models catalog.") with this GitHub Action. +> [AI inference request](https://docs.github.com/en/rest/models/inference#run-an-ai-inference-request "GitHub API documentation.") [GitHub Models](https://github.com/marketplace?type=models "GitHub Models catalog.") with this [GitHub Action](https://github.com/marketplace/actions/ai-inference-request-via-github-action "GitHub Actions marketplace.").
@@ -26,21 +26,21 @@ View [security policy and reporting instructions](SECURITY.md). ## Changelog -View [all notable changes](https://github.com/op5dev/inference-request/releases "Releases.") to this project in [Keep a Changelog](https://keepachangelog.com "Keep a Changelog.") format, which adheres to [Semantic Versioning](https://semver.org "Semantic Versioning."). +View [all notable changes](https://github.com/op5dev/ai-inference-request/releases "Releases.") to this project in [Keep a Changelog](https://keepachangelog.com "Keep a Changelog.") format, which adheres to [Semantic Versioning](https://semver.org "Semantic Versioning."). > [!TIP] > > All forms of **contribution are very welcome** and deeply appreciated for fostering open-source projects. > -> - [Create a PR](https://github.com/op5dev/inference-request/pulls "Create a pull request.") to contribute changes you'd like to see. -> - [Raise an issue](https://github.com/op5dev/inference-request/issues "Raise an issue.") to propose changes or report unexpected behavior. -> - [Open a discussion](https://github.com/op5dev/inference-request/discussions "Open a discussion.") to discuss broader topics or questions. -> - [Become a stargazer](https://github.com/op5dev/inference-request/stargazers "Become a stargazer.") if you find this project useful. +> - [Create a PR](https://github.com/op5dev/ai-inference-request/pulls "Create a pull request.") to contribute changes you'd like to see. +> - [Raise an issue](https://github.com/op5dev/ai-inference-request/issues "Raise an issue.") to propose changes or report unexpected behavior. +> - [Open a discussion](https://github.com/op5dev/ai-inference-request/discussions "Open a discussion.") to discuss broader topics or questions. +> - [Become a stargazer](https://github.com/op5dev/ai-inference-request/stargazers "Become a stargazer.") if you find this project useful.
## License - This project is licensed under the **permissive** [Apache License 2.0](LICENSE "Apache License 2.0."). -- All works herein are my own, shared of my own volition, and [contributors](https://github.com/op5dev/inference-request/graphs/contributors "Contributors."). +- All works herein are my own, shared of my own volition, and [contributors](https://github.com/op5dev/ai-inference-request/graphs/contributors "Contributors."). - Copyright 2016-present [Rishav Dhar](https://rdhar.dev "Rishav Dhar's profile.") — All wrongs reserved. diff --git a/SECURITY.md b/SECURITY.md index 1809ac5..754f224 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -17,4 +17,4 @@ Integrating security in your CI/CD pipeline is critical to practicing DevSecOps. ## Reporting a Vulnerability -You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead, sensitive bugs must be sent by email to or reported via [Security Advisory](https://github.com/op5dev/inference-request/security/advisories/new "Create a new security advisory."). +You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead, sensitive bugs must be sent by email to or reported via [Security Advisory](https://github.com/op5dev/ai-inference-request/security/advisories/new "Create a new security advisory."). From 10bf10a315026d5467c3846e8060bb023410783e Mon Sep 17 00:00:00 2001 From: Rishav Dhar <19497993+rdhar@users.noreply.github.com> Date: Sat, 7 Jun 2025 21:39:31 +0100 Subject: [PATCH 10/10] document input and output parameters Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --- .github/workflows/ci.yml | 5 ++-- README.md | 49 ++++++++++++++++++++++++++++++++++++++++ action.yml | 24 +++++++++++--------- 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5837462..9985a6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: permissions: contents: read # Required to checkout repository. - models: read # Required for model inference. + models: read # Required for AI inference. steps: - name: Echo context @@ -31,7 +31,8 @@ jobs: with: messages: '[{"role": "user", "content": "What is the capital of France?"}]' model: openai/o4-mini - org: op5dev + org: ${{ github.repository_owner}} + max-tokens: 100 - name: Echo outputs continue-on-error: true diff --git a/README.md b/README.md index ebdbb6d..16159f6 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,57 @@ ## Usage Examples +```yml +on: + issues: + types: opened + +jobs: + summary: + runs-on: ubuntu-latest + + permissions: + issues: write + models: read + + steps: + - name: Summarize issue + id: prompt + uses: op5dev/ai-inference-request@v2 + with: + messages: '[{"role": "user", "content": "Concisely summarize this GitHub issue titled ${{ github.event.issue.title }}: ${{ github.event.issue.body }}"}]' + model: openai/o4-mini + + - name: Comment summary + run: gh issue comment $NUMBER --body "$SUMMARY" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NUMBER: ${{ github.event.issue.number }} + SUMMARY: ${{ steps.prompt.outputs.response }} +``` +
+## Inputs + +Only `messages` and `model` are required inputs. [Compare available AI models](https://docs.github.com/en/copilot/using-github-copilot/ai-models/choosing-the-right-ai-model-for-your-task "Comparison of AI models for GitHub.") to choose the best one for your use-case. + +| Name | Description | +| -------------------- | ---------------------------------------------------------------------------------------------------- | +| `github-api-version` | GitHub API version.
Default: `2022-11-28` | +| `github-token` | GitHub token.
Default: `github.token` | +| `max-tokens` | Maximum number of tokens to generate in the completion.
Example: `1000` | +| `messages` | Messages to send to the model in JSON format.
Example: `[{"role": "user", "content": "Hello!"}]` | +| `model` | Model to use for inference.
Example: `openai/o4-mini` | +| `org` | Organization to which the request should be attributed.
Example: `github.repository_owner` | + +## Outputs + +| Name | Description | +| -------------- | -------------------------------------------- | +| `response` | Response content from the inference request. | +| `response-raw` | Raw, complete response in JSON format. | + ## Security View [security policy and reporting instructions](SECURITY.md). diff --git a/action.yml b/action.yml index 858d88d..ec5bf41 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ --- -name: Inference Request via GitHub Action +name: AI Inference Request via GitHub Action author: Rishav Dhar (https://rdhar.dev) -description: Run inference requests to GitHub Models with this GitHub Action. +description: AI inference request GitHub Models with this GitHub Action. inputs: github-api-version: @@ -10,19 +10,23 @@ inputs: required: false github-token: default: ${{ github.token }} - description: "GitHub token (e.g., `secrets.GITHUB_TOKEN`)." + description: "GitHub token (e.g., `github.token`)." + required: false + max-tokens: + default: "" + description: "Maximum number of tokens to generate in the completion (e.g., `1000`)." required: false messages: - default: "[]" + default: "" description: 'Messages to send to the model in JSON format (e.g., `[{"role": "user", "content": "Hello!"}]`).' required: true model: - default: "openai/o4-mini" + default: "" description: "Model to use for inference (e.g., `openai/o4-mini`)." required: true org: default: "" - description: "Organization to which the request should be attributed (e.g., `op5dev`)." + description: "Organization to which the request should be attributed (e.g., `github.repository_owner`)." required: false runs: @@ -43,23 +47,21 @@ runs: --header "Content-Type: application/json" \ --header "X-GitHub-Api-Version: $API_VERSION" \ --data '{ - "messages": [{"role": "user", "content": "What is the capital of France?"}], + "messages": ${{ inputs.messages }}, "model": "${{ inputs.model }}" }' ) - # "messages": '"${{ inputs.messages }}"', - # "model": '"${{ inputs.model }}"' echo $response_raw echo "response_raw=$response_raw" >> $GITHUB_OUTPUT echo "response=$response_raw | jq --raw-output '.choices[0].message.content'" >> $GITHUB_OUTPUT outputs: response: - description: "Placeholder." + description: "Response content from the inference request." value: ${{ steps.request.outputs.response }} response-raw: - description: "Placeholder." + description: "Raw, complete response in JSON format." value: ${{ steps.request.outputs.response_raw }} branding: