[PR #1426] [MERGED] fix: only flush template in chat when current role encountered #10580

Closed
opened 2026-04-12 23:03:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/1426
Author: @BruceMacD
Created: 12/8/2023
Status: Merged
Merged: 12/8/2023
Merged by: @BruceMacD

Base: mainHead: brucemacd/chat-template-bug


📝 Commits (2)

  • b998e0e fix: only flush template in chat when current role encountered
  • a06e114 test case

📊 Changes

2 files changed (+92 additions, -15 deletions)

View changed files

📝 server/images.go (+3 -3)
📝 server/images_test.go (+89 -12)

📄 Description

There was a bug in the /chat endpoint here during templating that resulted in the prompt template being written incorrectly.

If a user was encountered when the system was already set the template would be written before the user content was set. This was not correct. The template should only be written when the exact role has been encountered before.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/1426 **Author:** [@BruceMacD](https://github.com/BruceMacD) **Created:** 12/8/2023 **Status:** ✅ Merged **Merged:** 12/8/2023 **Merged by:** [@BruceMacD](https://github.com/BruceMacD) **Base:** `main` ← **Head:** `brucemacd/chat-template-bug` --- ### 📝 Commits (2) - [`b998e0e`](https://github.com/ollama/ollama/commit/b998e0ef04717f0410a7f8df7261d5e7ecb6d9e9) fix: only flush template in chat when current role encountered - [`a06e114`](https://github.com/ollama/ollama/commit/a06e1147180f74e9dd82bdf4d04b48c3233000c8) test case ### 📊 Changes **2 files changed** (+92 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `server/images.go` (+3 -3) 📝 `server/images_test.go` (+89 -12) </details> ### 📄 Description There was a bug in the /chat endpoint here during templating that resulted in the prompt template being written incorrectly. If a `user` was encountered when the `system` was already set the template would be written before the `user` content was set. This was not correct. The template should only be written when the exact role has been encountered before. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-12 23:03:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#10580