[PR #132] [CLOSED] Add type overloads for chat() method in _client.py #374

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

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama-python/pull/132
Author: @simonottenhauskenbun
Created: 4/26/2024
Status: Closed

Base: mainHead: typing


📝 Commits (1)

  • 6e25863 Add type overloads for chat() method in _client.py

📊 Changes

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

View changed files

📝 ollama/_client.py (+25 -1)

📄 Description

This PR adds two type overloads in _client.py to reduce type warnings.
The PR should only affect typing and no logic.

Before PR:

import ollama
response = ollama.chat(model='llama2', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])
# before PR: response is now Union[Mapping[str, Any], Iterator[Mapping[str, Any]]]
print(response['message']['content'])

New behaviour:

response = ollama.chat(model='llama2', stream=False, ...)
# response is of type Mapping[str, Any]

response = ollama.chat(model='llama2', stream=True, ...)
# response is of type Iterator[Mapping[str, Any]]

response = ollama.chat(model='llama2', ...)
# response is also of type Mapping[str, Any], since stream=False is the default.

🔄 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/132 **Author:** [@simonottenhauskenbun](https://github.com/simonottenhauskenbun) **Created:** 4/26/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `typing` --- ### 📝 Commits (1) - [`6e25863`](https://github.com/ollama/ollama-python/commit/6e2586371298332953433bd4364f608858ce7f35) Add type overloads for chat() method in _client.py ### 📊 Changes **1 file changed** (+25 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `ollama/_client.py` (+25 -1) </details> ### 📄 Description This PR adds two type overloads in `_client.py` to reduce type warnings. The PR should only affect typing and no logic. ## Before PR: ```python import ollama response = ollama.chat(model='llama2', messages=[ { 'role': 'user', 'content': 'Why is the sky blue?', }, ]) # before PR: response is now Union[Mapping[str, Any], Iterator[Mapping[str, Any]]] print(response['message']['content']) ``` ## New behaviour: ```python response = ollama.chat(model='llama2', stream=False, ...) # response is of type Mapping[str, Any] response = ollama.chat(model='llama2', stream=True, ...) # response is of type Iterator[Mapping[str, Any]] response = ollama.chat(model='llama2', ...) # response is also of type Mapping[str, Any], since stream=False is the default. ``` --- <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:09 -05:00
yindo closed this issue 2026-02-15 16:30:09 -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#374