Skip to content

Commit 9313f89

Browse files
authored
feat: prompt basic inference request (#5)
* feat: prompt basic inference request Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * comment Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * add codeowners Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * add ci workflow Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * hard-code input Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * reformat Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * sparse checkout Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * include org Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * rename project with "ai" prefix Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * document input and output parameters Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --------- Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>
1 parent 24c5b94 commit 9313f89

File tree

6 files changed

+177
-14
lines changed

6 files changed

+177
-14
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Each line is a file pattern followed by one or more owners.
2+
# Order is important as the last matching pair takes precedence.
3+
4+
* @rdhar @rdhar-tc

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: CI
3+
4+
on:
5+
pull_request:
6+
paths: [action.yml, .github/workflows/ci.yml]
7+
8+
jobs:
9+
CI:
10+
runs-on: [ubuntu-24.04]
11+
12+
permissions:
13+
contents: read # Required to checkout repository.
14+
models: read # Required for AI inference.
15+
16+
steps:
17+
- name: Echo context
18+
env:
19+
GH_JSON: ${{ toJson(github) }}
20+
run: echo "$GH_JSON"
21+
22+
- name: Checkout repository
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
persist-credentials: false
26+
sparse-checkout: action.yml
27+
28+
- name: Inference request
29+
id: prompt
30+
uses: ./
31+
with:
32+
messages: '[{"role": "user", "content": "What is the capital of France?"}]'
33+
model: openai/o4-mini
34+
org: ${{ github.repository_owner}}
35+
max-tokens: 100
36+
37+
- name: Echo outputs
38+
continue-on-error: true
39+
run: |
40+
echo "response: ${{ steps.prompt.outputs.response }}"
41+
echo "response-raw: ${{ steps.prompt.outputs.response-raw }}"

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: [ubuntu-24.04]
1111

1212
permissions:
13-
contents: write # Required to checkout repository.
13+
contents: write # Required to create tags.
1414
id-token: write # Required for authentication.
1515
packages: write # Required to publish packages.
1616

README.md

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,68 @@
1-
[![GitHub license](https://img.shields.io/github/license/op5dev/inference-request?logo=apache&label=License)](LICENSE "Apache License 2.0.")
2-
[![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.")
1+
[![GitHub license](https://img.shields.io/github/license/op5dev/ai-inference-request?logo=apache&label=License)](LICENSE "Apache License 2.0.")
2+
[![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.")
33
*
4-
[![GitHub repository stargazers](https://img.shields.io/github/stars/op5dev/inference-request)](https://github.com/op5dev/inference-request "Become a stargazer.")
4+
[![GitHub repository stargazers](https://img.shields.io/github/stars/op5dev/ai-inference-request)](https://github.com/op5dev/ai-inference-request "Become a stargazer.")
55

6-
# Inference Request via GitHub Action
6+
# AI Inference Request via GitHub Action
77

88
> [!TIP]
9-
> Run an inference request to GitHub Models via GitHub Action.
9+
> [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.").
1010
1111
</br>
1212

1313
## Usage Examples
1414

15+
```yml
16+
on:
17+
issues:
18+
types: opened
19+
20+
jobs:
21+
summary:
22+
runs-on: ubuntu-latest
23+
24+
permissions:
25+
issues: write
26+
models: read
27+
28+
steps:
29+
- name: Summarize issue
30+
id: prompt
31+
uses: op5dev/ai-inference-request@v2
32+
with:
33+
messages: '[{"role": "user", "content": "Concisely summarize this GitHub issue titled ${{ github.event.issue.title }}: ${{ github.event.issue.body }}"}]'
34+
model: openai/o4-mini
35+
36+
- name: Comment summary
37+
run: gh issue comment $NUMBER --body "$SUMMARY"
38+
env:
39+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
NUMBER: ${{ github.event.issue.number }}
41+
SUMMARY: ${{ steps.prompt.outputs.response }}
42+
```
43+
1544
</br>
1645
46+
## Inputs
47+
48+
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.
49+
50+
| Name | Description |
51+
| -------------------- | ---------------------------------------------------------------------------------------------------- |
52+
| `github-api-version` | GitHub API version.</br>Default: `2022-11-28` |
53+
| `github-token` | GitHub token.</br>Default: `github.token` |
54+
| `max-tokens` | Maximum number of tokens to generate in the completion.</br>Example: `1000` |
55+
| `messages` | Messages to send to the model in JSON format.</br>Example: `[{"role": "user", "content": "Hello!"}]` |
56+
| `model` | Model to use for inference.</br>Example: `openai/o4-mini` |
57+
| `org` | Organization to which the request should be attributed.</br>Example: `github.repository_owner` |
58+
59+
## Outputs
60+
61+
| Name | Description |
62+
| -------------- | -------------------------------------------- |
63+
| `response` | Response content from the inference request. |
64+
| `response-raw` | Raw, complete response in JSON format. |
65+
1766
## Security
1867

1968
View [security policy and reporting instructions](SECURITY.md).
@@ -26,21 +75,21 @@ View [security policy and reporting instructions](SECURITY.md).
2675

2776
## Changelog
2877

29-
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.").
78+
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.").
3079

3180
> [!TIP]
3281
>
3382
> All forms of **contribution are very welcome** and deeply appreciated for fostering open-source projects.
3483
>
35-
> - [Create a PR](https://github.com/op5dev/inference-request/pulls "Create a pull request.") to contribute changes you'd like to see.
36-
> - [Raise an issue](https://github.com/op5dev/inference-request/issues "Raise an issue.") to propose changes or report unexpected behavior.
37-
> - [Open a discussion](https://github.com/op5dev/inference-request/discussions "Open a discussion.") to discuss broader topics or questions.
38-
> - [Become a stargazer](https://github.com/op5dev/inference-request/stargazers "Become a stargazer.") if you find this project useful.
84+
> - [Create a PR](https://github.com/op5dev/ai-inference-request/pulls "Create a pull request.") to contribute changes you'd like to see.
85+
> - [Raise an issue](https://github.com/op5dev/ai-inference-request/issues "Raise an issue.") to propose changes or report unexpected behavior.
86+
> - [Open a discussion](https://github.com/op5dev/ai-inference-request/discussions "Open a discussion.") to discuss broader topics or questions.
87+
> - [Become a stargazer](https://github.com/op5dev/ai-inference-request/stargazers "Become a stargazer.") if you find this project useful.
3988

4089
</br>
4190

4291
## License
4392

4493
- This project is licensed under the **permissive** [Apache License 2.0](LICENSE "Apache License 2.0.").
45-
- All works herein are my own, shared of my own volition, and [contributors](https://github.com/op5dev/inference-request/graphs/contributors "Contributors.").
46-
- Copyright 2016-present [Rishav Dhar](https://github.com/rdhar "Rishav Dhar's GitHub profile.") — All wrongs reserved.
94+
- All works herein are my own, shared of my own volition, and [contributors](https://github.com/op5dev/ai-inference-request/graphs/contributors "Contributors.").
95+
- Copyright 2016-present [Rishav Dhar](https://rdhar.dev "Rishav Dhar's profile.") — All wrongs reserved.

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ Integrating security in your CI/CD pipeline is critical to practicing DevSecOps.
1717

1818
## Reporting a Vulnerability
1919

20-
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.").
20+
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.").

action.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
name: AI Inference Request via GitHub Action
3+
author: Rishav Dhar (https://rdhar.dev)
4+
description: AI inference request GitHub Models with this GitHub Action.
5+
6+
inputs:
7+
github-api-version:
8+
default: "2022-11-28"
9+
description: "GitHub API version (e.g., `2022-11-28`)."
10+
required: false
11+
github-token:
12+
default: ${{ github.token }}
13+
description: "GitHub token (e.g., `github.token`)."
14+
required: false
15+
max-tokens:
16+
default: ""
17+
description: "Maximum number of tokens to generate in the completion (e.g., `1000`)."
18+
required: false
19+
messages:
20+
default: ""
21+
description: 'Messages to send to the model in JSON format (e.g., `[{"role": "user", "content": "Hello!"}]`).'
22+
required: true
23+
model:
24+
default: ""
25+
description: "Model to use for inference (e.g., `openai/o4-mini`)."
26+
required: true
27+
org:
28+
default: ""
29+
description: "Organization to which the request should be attributed (e.g., `github.repository_owner`)."
30+
required: false
31+
32+
runs:
33+
using: composite
34+
steps:
35+
- id: request
36+
shell: bash
37+
env:
38+
API_VERSION: ${{ inputs.github-api-version }}
39+
GH_TOKEN: ${{ inputs.github-token }}
40+
ORG: ${{ inputs.org != '' && format('orgs/{0}/', inputs.org) || '' }}
41+
run: |
42+
GH_HOST=$(echo $GITHUB_SERVER_URL | sed 's/.*:\/\///')
43+
44+
response_raw=$(curl --request POST --location https://models.github.ai/${ORG}inference/chat/completions \
45+
--header "Accept: application/vnd.github+json" \
46+
--header "Authorization: Bearer $GH_TOKEN" \
47+
--header "Content-Type: application/json" \
48+
--header "X-GitHub-Api-Version: $API_VERSION" \
49+
--data '{
50+
"messages": ${{ inputs.messages }},
51+
"model": "${{ inputs.model }}"
52+
}'
53+
)
54+
55+
echo $response_raw
56+
echo "response_raw=$response_raw" >> $GITHUB_OUTPUT
57+
echo "response=$response_raw | jq --raw-output '.choices[0].message.content'" >> $GITHUB_OUTPUT
58+
59+
outputs:
60+
response:
61+
description: "Response content from the inference request."
62+
value: ${{ steps.request.outputs.response }}
63+
response-raw:
64+
description: "Raw, complete response in JSON format."
65+
value: ${{ steps.request.outputs.response_raw }}
66+
67+
branding:
68+
color: white
69+
icon: loader

0 commit comments

Comments
 (0)