$ show actions/ai-inference
This repository implements a GitHub Action (`actions/ai-inference`) that runs AI model inference inside GitHub Actions workflows by shelling out to the GitHub Copilot CLI. The action accepts a user prompt (inline or from a file), an optional system prompt, a model identifier, and various configuration options. It builds a combined prompt string, spawns the Copilot CLI with `-p`, `-s`, and `--no-ask-user` flags, captures the model's text response, and exposes it via `response` and `response-file` outputs. The architecture is a single Node.js action (bundled into `dist/index.js`) with modular TypeScript source files: `main.ts` orchestrates input parsing and provider dispatch, `copilot.ts` handles CLI invocation and error handling, `prompt.ts` provides structured `.prompt.yml` file parsing with template variable substitution, and `helpers.ts` contains utility functions. The action is tightly coupled to the Copilot CLI, which must be pre-installed and authenticated on the runner. It supports only the `copilot` provider. The codebase is well-structured, includes unit tests, and follows modern TypeScript practices.
The LLM identified 2 files worth highlighting for reuse:
Provides a reusable module for parsing `.prompt.yml` files, including template variable substitution (using `{{variable}}` syntax), validation of message roles, and support for JSON schema response formats. The `loadPromptFile`, `parseTemplateVariables`, and `replaceTemplateVariables` functions are self-contained and could be extracted into a separate library for any project that needs to process structured prompt files with variable injection. The module demonstrates clean separation of concerns and robust error handling.
Encapsulates the logic for spawning the Copilot CLI, building the argument list, and handling stdout/stderr. The `buildCopilotPrompt` function correctly separates system and user messages, and the `copilotInference` function provides a clean async interface with a configurable spawner (enabling testability). The module handles ENOENT errors with a helpful message, masks tokens in logs, and avoids leaking stderr in error messages. This pattern is reusable for any action that needs to wrap a CLI tool.