[PR #118] [MERGED] fix 'content' check on messages in chat() #366

Closed
opened 2026-02-15 16:30:08 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama-python/pull/118
Author: @DSLstandard
Created: 4/15/2024
Status: Merged
Merged: 4/24/2024
Merged by: @mxyng

Base: mainHead: fix-content-check


📝 Commits (1)

  • dc9543b fix 'content' check on messages in chat()

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 ollama/_client.py (+2 -2)

📄 Description

In chat() in Client and AsyncClient, if message['content'] is "",

the following would raise an error since bool("") also returns False like bool(None):

if not message.get('content'):
  raise RequestError('messages must contain content')

Doing the following would fix it:

if 'content' not in message:
  raise RequestError('messages must contain content')

As far as I know ollama does not explicitly prohibit empty content in messages.


🔄 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-python/pull/118 **Author:** [@DSLstandard](https://github.com/DSLstandard) **Created:** 4/15/2024 **Status:** ✅ Merged **Merged:** 4/24/2024 **Merged by:** [@mxyng](https://github.com/mxyng) **Base:** `main` ← **Head:** `fix-content-check` --- ### 📝 Commits (1) - [`dc9543b`](https://github.com/ollama/ollama-python/commit/dc9543ba5f6120d8fa46fad30ba650414b7f4a35) fix 'content' check on messages in chat() ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `ollama/_client.py` (+2 -2) </details> ### 📄 Description In `chat()` in `Client` and `AsyncClient`, if `message['content']` is `""`, the following would raise an error since `bool("")` also returns `False` like `bool(None)`: ```python if not message.get('content'): raise RequestError('messages must contain content') ``` Doing the following would fix it: ```python if 'content' not in message: raise RequestError('messages must contain content') ``` As far as I know ollama does not explicitly prohibit empty content in messages. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 16:30:08 -05:00
yindo closed this issue 2026-02-15 16:30:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#366