[PR #5126] [MERGED] update message processing #11691

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

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/5126
Author: @mxyng
Created: 6/19/2024
Status: Merged
Merged: 7/9/2024
Merged by: @mxyng

Base: mainHead: mxyng/messages


📝 Commits (4)

📊 Changes

7 files changed (+677 additions, -709 deletions)

View changed files

📝 llm/server.go (+1 -1)
📝 server/images.go (+13 -4)
📝 server/prompt.go (+53 -187)
📝 server/prompt_test.go (+155 -166)
📝 server/routes.go (+157 -339)
📝 template/template.go (+138 -8)
📝 template/template_test.go (+160 -4)

📄 Description

this change changes the way messages are processed before handing off to the llm. there are a few areas worth mentioning:

  1. messages are now a first class component of the template. template rendering will only falling back to the previous iterative template if messages is unsupported by the template. however, new models should implement the previous prompt/response template for compatibility with older ollama versions

  2. the generate endpoint has been updated to use messages for prompt templating but the end result should be the same

  3. the chat endpoint has been updated to preprocess incoming messages

    • continuous messages of the same role are joined into a single message, separated with two newlines
    • content and image data can be interleaved by sending messages with alternating fields, e.g.
      [
          {"role": "user", "content": "Consider the following images:"},
          {"role": "user", "images": ["<base64 image data>", "<base64 image data>"]},
          {"role": "user", "content": "What is the difference between the two images?"}
      ]
      
    • system messages are aggregated and prepended to the last user message

🔄 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/5126 **Author:** [@mxyng](https://github.com/mxyng) **Created:** 6/19/2024 **Status:** ✅ Merged **Merged:** 7/9/2024 **Merged by:** [@mxyng](https://github.com/mxyng) **Base:** `main` ← **Head:** `mxyng/messages` --- ### 📝 Commits (4) - [`269ed6e`](https://github.com/ollama/ollama/commit/269ed6e6a2cea822ab137d40d5c70c8bf09470f8) update message processing - [`2c3fe1f`](https://github.com/ollama/ollama/commit/2c3fe1fd972b7810091120f844afc35bc98accbd) comments - [`ac7a842`](https://github.com/ollama/ollama/commit/ac7a842e550721fbc00e36e416e7cf6606993149) fix model reloading - [`326363b`](https://github.com/ollama/ollama/commit/326363b3a72d9e2972a019dfc4c6147ea901f501) no funcs ### 📊 Changes **7 files changed** (+677 additions, -709 deletions) <details> <summary>View changed files</summary> 📝 `llm/server.go` (+1 -1) 📝 `server/images.go` (+13 -4) 📝 `server/prompt.go` (+53 -187) 📝 `server/prompt_test.go` (+155 -166) 📝 `server/routes.go` (+157 -339) 📝 `template/template.go` (+138 -8) 📝 `template/template_test.go` (+160 -4) </details> ### 📄 Description this change changes the way messages are processed before handing off to the llm. there are a few areas worth mentioning: 1. messages are now a first class component of the template. template rendering will only falling back to the previous iterative template if messages is unsupported by the template. however, new models _should_ implement the previous prompt/response template for compatibility with older ollama versions 2. the generate endpoint has been updated to use messages for prompt templating but the end result should be the same 3. the chat endpoint has been updated to preprocess incoming messages - continuous messages of the same role are joined into a single message, separated with two newlines - content and image data can be interleaved by sending messages with alternating fields, e.g. ``` [ {"role": "user", "content": "Consider the following images:"}, {"role": "user", "images": ["<base64 image data>", "<base64 image data>"]}, {"role": "user", "content": "What is the difference between the two images?"} ] ``` - system messages are aggregated and prepended to the _last_ user message --- <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:36:00 -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#11691