[GH-ISSUE #7342] Add 'prefix' option to chat endpoint #4665

Closed
opened 2026-04-12 15:35:07 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Smorty10 on GitHub (Oct 24, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7342

Problem

Limited control over output from chat endpoint

Limitation

No formatting options besides "format"="json"

Required Feature

Adding a "prefix" key to the chat endpoint, so we can define a prefix for the models response

Usage

var query:JSON = {
    "model":"llama3.2",
    "messages":some_conversation_defined_earlier,
    "prefix":"Here is my chain of thought:\n"
}

Final generated message:

Here is my chain of thought:
1. Split up the tasks into more managabe ones
2. Some other step
...

I am assuming that this is also how "format":"json" works: Defining a prefix for the chat response (presumably ```json\n{)

Benefits

This feature would make ollama users able to define their own prefix formats, essentially making "format":"json" obsolete (it's still nice to have the option though, for backwards-compatebility and convenience).

Originally created by @Smorty10 on GitHub (Oct 24, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7342 ## Problem Limited control over output from chat endpoint ## Limitation No formatting options besides `"format"="json"` ## Required Feature Adding a `"prefix"` key to the chat endpoint, so we can define a prefix for the models response ## Usage ```pseudocode var query:JSON = { "model":"llama3.2", "messages":some_conversation_defined_earlier, "prefix":"Here is my chain of thought:\n" } ``` Final generated message: ```plaintext Here is my chain of thought: 1. Split up the tasks into more managabe ones 2. Some other step ... ``` I am assuming that this is also how `"format":"json"` works: Defining a prefix for the chat response (presumably ` ```json\n{ `) ## Benefits This feature would make ollama users able to define their own prefix formats, essentially making `"format":"json"` obsolete (it's still nice to have the option though, for backwards-compatebility and convenience).
GiteaMirror added the feature request label 2026-04-12 15:35:07 -05:00
Author
Owner

@jmorganca commented on GitHub (Oct 24, 2024):

Hi there, thanks for the issue. This can be done with the chat API by providing the beginning of an assistant message:

curl http://localhost:11434/api/chat -d '{
  "model": "llama3.2",
  "messages": [
    {
      "role": "user",
      "content": "why is the sky blue?"
    },
    {
      "role": "assistant",
      "content": "Here is my chain of thought:\n"
    }
  ]
}'
<!-- gh-comment-id:2435747068 --> @jmorganca commented on GitHub (Oct 24, 2024): Hi there, thanks for the issue. This can be done with the chat API by providing the beginning of an assistant message: ``` curl http://localhost:11434/api/chat -d '{ "model": "llama3.2", "messages": [ { "role": "user", "content": "why is the sky blue?" }, { "role": "assistant", "content": "Here is my chain of thought:\n" } ] }' ```
Author
Owner

@Smorty10 commented on GitHub (Oct 24, 2024):

@jmorganca Is this kind of prefix also possible with the generate endpoint?

<!-- gh-comment-id:2436396184 --> @Smorty10 commented on GitHub (Oct 24, 2024): @jmorganca Is this kind of prefix also possible with the generate endpoint?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#4665