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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9985a6f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +--- +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 AI 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 + sparse-checkout: action.yml + + - name: Inference request + id: prompt + uses: ./ + with: + messages: '[{"role": "user", "content": "What is the capital of France?"}]' + model: openai/o4-mini + org: ${{ github.repository_owner}} + max-tokens: 100 + + - name: Echo outputs + continue-on-error: true + run: | + echo "response: ${{ steps.prompt.outputs.response }}" + echo "response-raw: ${{ steps.prompt.outputs.response-raw }}" 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. diff --git a/README.md b/README.md index a1b9589..16159f6 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,68 @@ -[![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 an inference request to GitHub Models via 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.").
## 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). @@ -26,21 +75,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."). -- Copyright 2016-present [Rishav Dhar](https://github.com/rdhar "Rishav Dhar's GitHub profile.") — All wrongs reserved. +- 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."). diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ec5bf41 --- /dev/null +++ b/action.yml @@ -0,0 +1,69 @@ +--- +name: AI Inference Request via GitHub Action +author: Rishav Dhar (https://rdhar.dev) +description: AI inference request 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., `github.token`)." + required: false + max-tokens: + default: "" + description: "Maximum number of tokens to generate in the completion (e.g., `1000`)." + required: false + messages: + default: "" + description: 'Messages to send to the model in JSON format (e.g., `[{"role": "user", "content": "Hello!"}]`).' + required: true + model: + 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., `github.repository_owner`)." + required: false + +runs: + using: composite + steps: + - id: request + shell: bash + env: + API_VERSION: ${{ inputs.github-api-version }} + GH_TOKEN: ${{ inputs.github-token }} + ORG: ${{ inputs.org != '' && format('orgs/{0}/', inputs.org) || '' }} + run: | + 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" \ + --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 + echo "response_raw=$response_raw" >> $GITHUB_OUTPUT + echo "response=$response_raw | jq --raw-output '.choices[0].message.content'" >> $GITHUB_OUTPUT + +outputs: + response: + description: "Response content from the inference request." + value: ${{ steps.request.outputs.response }} + response-raw: + description: "Raw, complete response in JSON format." + value: ${{ steps.request.outputs.response_raw }} + +branding: + color: white + icon: loader