|
| 1 | +--- |
| 2 | +name: Inference Request via GitHub Action |
| 3 | +author: Rishav Dhar (https://rdhar.dev) |
| 4 | +description: Run inference requests to 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., `secrets.GITHUB_TOKEN`)." |
| 14 | + required: false |
| 15 | + messages: |
| 16 | + default: "[]" |
| 17 | + description: 'Messages to send to the model in JSON format (e.g., `[{"role": "user", "content": "Hello!"}]`).' |
| 18 | + required: true |
| 19 | + model: |
| 20 | + default: "openai/o4-mini" |
| 21 | + description: "Model to use for inference (e.g., `openai/o4-mini`)." |
| 22 | + required: true |
| 23 | + org: |
| 24 | + default: "" |
| 25 | + description: "Organization to which the request should be attributed (e.g., `op5dev`)." |
| 26 | + required: false |
| 27 | + |
| 28 | +runs: |
| 29 | + using: composite |
| 30 | + steps: |
| 31 | + - id: request |
| 32 | + shell: bash |
| 33 | + env: |
| 34 | + API_VERSION: ${{ inputs.github-api-version }} |
| 35 | + GH_HOST: ${{ github.server_url }} |
| 36 | + GH_TOKEN: ${{ inputs.github-token }} |
| 37 | + ORG: ${{ inputs.org != '' && format('orgs/{0}/', inputs.org) || '' }} |
| 38 | + run: | |
| 39 | + GH_HOST=$(echo $GH_HOST | sed 's/.*:\/\///') |
| 40 | +
|
| 41 | + response_raw=$(curl --request POST --location https://models.github.ai/${ORG}inference/chat/completions \ |
| 42 | + --header "Accept: application/vnd.github+json" \ |
| 43 | + --header "Authorization: Bearer $GH_TOKEN" \ |
| 44 | + --header "Content-Type: application/json" \ |
| 45 | + --header "X-GitHub-Api-Version: $API_VERSION" \ |
| 46 | + --data '{ |
| 47 | + "messages": '"${{ inputs.messages }}"', |
| 48 | + "model": '"${{ inputs.model }}"' |
| 49 | + }') |
| 50 | +
|
| 51 | + echo "response_raw=$response_raw" >> $GITHUB_OUTPUT |
| 52 | + echo "response=$response_raw | jq --raw-output '.choices[0].message.content'" >> $GITHUB_OUTPUT |
| 53 | +
|
| 54 | +outputs: |
| 55 | + response: |
| 56 | + description: "Placeholder." |
| 57 | + value: ${{ steps.request.outputs.response }} |
| 58 | + response-raw: |
| 59 | + description: "Placeholder." |
| 60 | + value: ${{ steps.request.outputs.response_raw }} |
| 61 | + |
| 62 | +branding: |
| 63 | + color: white |
| 64 | + icon: loader |
0 commit comments