Skip to content

Conversation

@sgoedecke
Copy link
Collaborator

Supports passing multiple variables to a prompt file with gh models run, e.g. gh models run --file prompt.yml --var name=Alice --var topic="machine learning"

@sgoedecke ➜ /workspaces/gh-models (main) $ ./gh-models run --file examples/template_variables_prompt.yml --var name=S
ean --var topic=Dog --var input=help
Hi there! It seems like you might need some assistance related to dogs.

@sgoedecke ➜ /workspaces/gh-models (main) $ ./gh-models run --file examples/template_variables_prompt.yml --var name=Sean --var topic=Dog --var ="what is my name"
Error: variable key cannot be empty in '=what is my name'

Copilot AI review requested due to automatic review settings June 11, 2025 22:56
@sgoedecke sgoedecke requested a review from a team as a code owner June 11, 2025 22:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables passing multiple template variables to prompt files in the gh models run command and wires them through to the templating engine.

  • Introduce a new --var flag and parsing logic for key=value pairs.
  • Merge custom variables with the existing input before templating prompt file messages.
  • Add unit tests for the parseTemplateVariables helper.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
examples/template_variables_prompt.yml New basic example showing variable placeholders in a prompt file.
examples/advanced_template_prompt.yml New advanced example with multiple template variables and blocks.
cmd/run/run_test.go Added TestParseTemplateVariables to cover a variety of flag scenarios.
cmd/run/run.go Registered --var flag, parsing logic, and injected variables into templating.
Comments suppressed due to low confidence (3)

cmd/run/run.go:406

  • Clarify the flag description to indicate the required key=value format and that empty entries are skipped, e.g.: "Template variables in key=value format (skip blank), can be repeated".
cmd.Flags().StringSlice("var", []string{}, "Template variables for prompt files (can be used multiple times: --var name=value)")

cmd/run/run.go:299

  • Consider adding an integration or end-to-end test that runs NewRunCommand with a prompt file and --var flags to verify placeholders in pf.Messages are correctly replaced.
for key, value := range templateVars {

examples/template_variables_prompt.yml:1

  • Add a CLI usage snippet (e.g. # gh models run --file template_variables_prompt.yml --var name=Alice --var topic=Pets) to illustrate how to invoke this example.
# Example demonstrating arbitrary template variables

@sgoedecke sgoedecke merged commit 8ca624c into main Jun 11, 2025
5 checks passed
@sgoedecke sgoedecke deleted the sgoedecke/multiple-variables-in-run branch June 11, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants