read prompt from file and print output to file

This commit is contained in:
Aiqiao Yan
2025-04-17 17:41:35 +00:00
parent c7105a4c1e
commit 43f6a3831f
8 changed files with 123 additions and 34 deletions

View File

@@ -34,6 +34,30 @@ jobs:
run: echo "${{ steps.inference.outputs.response }}"
```
### Using a Prompt File
You can also provide a prompt file instead of an inline prompt:
```yaml
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run AI Inference with Prompt File
id: inference
uses: actions/ai-inference@v1
with:
prompt-file: './path/to/prompt.txt'
- name: Use Response File
run: |
echo "Response saved to: ${{ steps.inference.outputs.response-path }}"
cat "${{ steps.inference.outputs.response-path }}"
```
This is particularly useful for longer prompts or when you need to use the file
path where the response is stored.
## Inputs
Various inputs are defined in [`action.yml`](action.yml) to let you configure
@@ -43,6 +67,7 @@ the action:
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| `token` | Token to use for inference. Typically the GITHUB_TOKEN secret | `github.token` |
| `prompt` | The prompt to send to the model | N/A |
| `prompt-file` | Path to a file containing the prompt. If both `prompt` and `prompt-file` are provided, `prompt-file` takes precedence | `""` |
| `system-prompt` | The system prompt to send to the model | `""` |
| `model` | The model to use for inference. Must be available in the [GitHub Models](https://github.com/marketplace?type=models) catalog | `gpt-4o` |
| `endpoint` | The endpoint to use for inference. If you're running this as part of an org, you should probably use the org-specific Models endpoint | `https://models.github.ai/inference` |
@@ -52,9 +77,10 @@ the action:
The AI inference action provides the following outputs:
| Name | Description |
| ---------- | --------------------------- |
| `response` | The response from the model |
| Name | Description |
| --------------- | ----------------------------------------------------------------------- |
| `response` | The response from the model |
| `response-path` | The file path where the response is saved (useful for larger responses) |
## Required Permissions