llm icon indicating copy to clipboard operation
llm copied to clipboard

Add `--input-style` feature for `prompt`

Open akx opened this issue 11 months ago • 4 comments

This adds --input-style for llm prompt, which lets the operator choose how input from stdin is passed to the prompt.

For llm prompt "describe this" and input from stdin as the input, the final prompts would be:

--input-style=prepend (the default, and the current behavior)

input from stdin describe this

--input-style=append

describe this input from stdin

--input-style=fence-prepend

```
input from stdin
```

describe this

--input-style=fence-append

describe this

```
input from stdin
```

akx avatar Dec 30 '24 11:12 akx

Gentle review nudge, @simonw? 😅

akx avatar Jan 14 '25 15:01 akx

Why would you need this?

I mean you can do: (cat somefile; echo "describe this") | llm

or (echo "describe this" ; cat somefile) | llm

or (echo "describe this\n\n"'```' ; cat summarize.sh ; echo '```') | llm if you really want.

Grynn avatar Jan 14 '25 16:01 Grynn

@Grynn Well, all of those are much less convenient to type and iterate upon than this option.

akx avatar Jan 14 '25 19:01 akx

This just became even more relevant with this section of the GPT 4.1 prompting guide, emphasis mine:

Especially in long context usage, placement of instructions and context can impact performance. If you have long context in your prompt, ideally place your instructions at both the beginning and end of the provided context, as we found this to perform better than only above or below. If you’d prefer to only have your instructions once, then above the provided context works better than below.

I rebased this and added both and fence-both.

cc @simonw :)

akx avatar Apr 15 '25 10:04 akx