Skip to content

Include initial prompt when interpolating {{input}} in prompt.yaml files #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2025

Conversation

phillmv
Copy link
Member

@phillmv phillmv commented May 16, 2025

Hello!

What?

This PR makes it so that the text that is substituted when interpolating {{input}} templates inside prompt.yaml files includes whatever got piped in AND the "initial prompt", i.e. the text that is passed in via the positional args.

Why?

I am stringing gh models run together as a cli util for my own GitHub work related purposes, and I like the idea of having templated system prompts I can swap out at will. I've seen a few people online claim that messing with system prompts is where a lot of the "juice" is, and I find that for ex. the default gpt-4o behaviour is overly verbose and obsequious.

Initially, using --file prompt.yaml seemed pretty ideal for this. However, I quickly discovered that the {{input}} template was not being populated with the contents of the "initialPrompt" – only with whatever got piped in.

This made it inconvenient to use with my intended use case, i.e. something like this:

alias gmr="gh models run openai/gpt-4o --file prompts/default.prompt.yaml"

cat whatever.txt | grm sample prompt here but for example let's say translate this file into ruby

Without this change, the specific request to "translate this file into ruby" gets ignored.

Additional improvements

Typing this out, I feel like that this should be the default behaviour, i.e. even if the provided prompt.yaml does not specify an {{input}} field but the run command receives piped or prompted content, then we should throw that in as user message. If I am feeling frisky maybe I could add that in a future PR.

@Copilot Copilot AI review requested due to automatic review settings May 16, 2025 19:54
@phillmv phillmv requested a review from a team as a code owner May 16, 2025 19:54
Copy link
Contributor

@Copilot 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 updates the gh models run command so that when a prompt file uses {{input}}, it is replaced by both the positional initial prompt and any piped stdin content.

  • Added gopkg.in/yaml.v3 dependency
  • Adjusted run.go to merge initialPrompt and pipedContent for templating
  • Updated run_test.go to verify combined prompt and stdin behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
go.mod Added YAML v3 dependency and removed duplicate indirect require
cmd/run/run.go Changed stdin handling to prepend positional args to piped input
cmd/run/run_test.go Renamed test and updated assertion for combined prompt and stdin
Comments suppressed due to low confidence (1)

cmd/run/run.go:274

  • Reading piped stdin without positional args does not set singleShot=true, so the loop will unexpectedly enter interactive mode. Set singleShot = true when content comes from stdin to preserve single-shot behavior.
if initialPrompt != "" {

Copy link
Collaborator

@sgoedecke sgoedecke left a comment

Choose a reason for hiding this comment

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

Thank you!

@sgoedecke sgoedecke merged commit 81f5047 into main May 19, 2025
5 checks passed
@sgoedecke sgoedecke deleted the phillmv/templated-input-should-include-initial-prompt branch May 19, 2025 03:12
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.

2 participants