Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
73 changes: 61 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.").

</br>

## 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 }}
```

</br>

## 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.</br>Default: `2022-11-28` |
| `github-token` | GitHub token.</br>Default: `github.token` |
| `max-tokens` | Maximum number of tokens to generate in the completion.</br>Example: `1000` |
| `messages` | Messages to send to the model in JSON format.</br>Example: `[{"role": "user", "content": "Hello!"}]` |
| `model` | Model to use for inference.</br>Example: `openai/o4-mini` |
| `org` | Organization to which the request should be attributed.</br>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).
Expand All @@ -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.

</br>

## 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.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <contact@OP5.dev> 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 <contact@OP5.dev> or reported via [Security Advisory](https://github.com/op5dev/ai-inference-request/security/advisories/new "Create a new security advisory.").
69 changes: 69 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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