[GH-ISSUE #2630] OpenAI API adds both system prompts from model card and from request #1552

Closed
opened 2026-04-12 11:27:47 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @hoblin on GitHub (Feb 21, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2630

Hey there. Is there any way to override the model's default system prompt when I use the OpenAI API endpoint?
The request had a system prompt CUSTOM_SYSTEM_PROMPT and a user message Hello.
That's the resulting prompt from the server.log file:

time=2024-02-21T12:09:22.158+02:00 level=DEBUG source=routes.go:1205 msg="chat handler" prompt="<|im_start|>system\nYou are Dolphin, a helpful AI assistant.\n<|im_end|>\n<|im_start|>user\n<|im_end|>\n<|im_start|>assistant\n<|im_start|>system\nCUSTOM_SYSTEM_PROMPT\n<|im_end|>\n<|im_start|>user\n Hello.<|im_end|>\n<|im_start|>assistant\n<|im_start|>system\n<|im_end|>\n<|im_start|>user\n Hello.<|im_end|>\n<|im_start|>assistant\n" images=0
Originally created by @hoblin on GitHub (Feb 21, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2630 Hey there. Is there any way to override the model's default system prompt when I use the OpenAI API endpoint? The request had a system prompt `CUSTOM_SYSTEM_PROMPT` and a user message `Hello.` That's the resulting prompt from the server.log file: ```server.log time=2024-02-21T12:09:22.158+02:00 level=DEBUG source=routes.go:1205 msg="chat handler" prompt="<|im_start|>system\nYou are Dolphin, a helpful AI assistant.\n<|im_end|>\n<|im_start|>user\n<|im_end|>\n<|im_start|>assistant\n<|im_start|>system\nCUSTOM_SYSTEM_PROMPT\n<|im_end|>\n<|im_start|>user\n Hello.<|im_end|>\n<|im_start|>assistant\n<|im_start|>system\n<|im_end|>\n<|im_start|>user\n Hello.<|im_end|>\n<|im_start|>assistant\n" images=0 ```
Author
Owner

@robertvazan commented on GitHub (Feb 23, 2024):

I can confirm that including system prompt results in malformed prompt being fed to the LLM.

Request:

{
  "model": "dolphin-mistral:latest",
  "messages": [
    {
      "role": "system",
      "content": "Answer every question in French."
    },
    {
      "role": "user",
      "content": "How big is the universe?"
    },
    {
      "role": "assistant",
      "content": ""
    }
  ],
  "options": {},
  "keep_alive": "1h"
}

Malformed prompt:

<|im_start|>system
You are Dolphin, a helpful AI assistant.
<|im_end|>
<|im_start|>user
<|im_end|>
<|im_start|>assistant
<|im_start|>system
Answer every question in French.<|im_end|>
<|im_start|>user
How big is the universe?<|im_end|>
<|im_start|>assistant

The same happens if I remove the last empty assistant message from the request.

<!-- gh-comment-id:1960743035 --> @robertvazan commented on GitHub (Feb 23, 2024): I can confirm that including system prompt results in malformed prompt being fed to the LLM. Request: ```json { "model": "dolphin-mistral:latest", "messages": [ { "role": "system", "content": "Answer every question in French." }, { "role": "user", "content": "How big is the universe?" }, { "role": "assistant", "content": "" } ], "options": {}, "keep_alive": "1h" } ``` Malformed prompt: ``` <|im_start|>system You are Dolphin, a helpful AI assistant. <|im_end|> <|im_start|>user <|im_end|> <|im_start|>assistant <|im_start|>system Answer every question in French.<|im_end|> <|im_start|>user How big is the universe?<|im_end|> <|im_start|>assistant ``` The same happens if I remove the last empty assistant message from the request.
Author
Owner

@robertvazan commented on GitHub (Feb 23, 2024):

Just pulled the latest release and this seems fixed.

<!-- gh-comment-id:1960805222 --> @robertvazan commented on GitHub (Feb 23, 2024): Just pulled the latest release and this seems fixed.
Author
Owner

@hoblin commented on GitHub (Feb 23, 2024):

Yup, just tested. Prompt works as expected now. Great job ollama team!

<!-- gh-comment-id:1961338650 --> @hoblin commented on GitHub (Feb 23, 2024): Yup, just tested. Prompt works as expected now. Great job ollama team!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#1552