QV Ollama SDK
A simple SDK for interacting with the Ollama API with thinking mode and tool calling support.
Features
- 🧠 Thinking Mode - See AI reasoning process before answers
- 🛠️ Tool Calling - Execute Python functions automatically
- 💬 Simple Conversation - Easy chat interface
- ⚡ Streaming Support - Real-time responses
- 🔧 Explicit Parameters - No unnecessary defaults
- 🛡️ Model Compatibility - Auto-fallback for unsupported features
Installation
pip install qv-ollama-sdk
Quick Start
from qv_ollama_sdk import OllamaChatClient
# Create a client with a system message
client = OllamaChatClient(
model_name="qwen3:8b",
system_message="You are a helpful assistant."
)
# Simple chat - uses Ollama's default parameters
response = client.chat("What is the capital of France?")
print(response.content)
# Continue the conversation
response = client.chat("And what is its population?")
print(response.content)
# Set specific parameters only when you need them
client.temperature = 1.0 # Using property setter
client.max_tokens = 500 # Using property setter
client.set_parameters(num_ctx=2048) # For multiple parameters
# Get conversation history
history = client.get_history()
🧠 Thinking Mode
# Enable thinking globally
client.enable_thinking()
response = client.chat("Solve this complex problem...")
print(f"🧠 Thinking: {response.thinking}")
print(f"💬 Answer: {response.content}")
# Disable when you want fast responses
client.disable_thinking()
🛠️ Tool Calling
def add_numbers(a: str, b: str) -> str:
"""Add two numbers."""
return str(int(a) + int(b))
def get_weather(city: str) -> str:
"""Get weather for a city."""
return f"Sunny in {city}, 23°C"
tools = [add_numbers, get_weather]
# AI automatically calls functions when needed
response = client.chat("What's 15+27? And weather in Berlin?", tools=tools)
print(response.content)
🎯 Thinking + Tools
client.enable_thinking()
response = client.chat("Calculate 25 + 18", tools=tools)
print(f"🧠 Thinking: {response.thinking}")
print(f"💬 Answer: {response.content}")
print(f"🛠️ Tools used: {len(response.tool_calls)}")
⚡ Streaming
# Stream with thinking and tools
for chunk in client.stream_chat("Add 12 + 8", tools=tools):
if chunk.thinking:
print(chunk.thinking, end="")
if chunk.tool_calls:
print(f"🛠️ Using: {chunk.tool_calls[0].function.name}")
if chunk.content:
print(chunk.content, end="")
API Reference
Main Methods
chat(message, tools=None, auto_execute=True)- Get responsestream_chat(message, tools=None, auto_execute=True)- Stream response
Thinking Control
enable_thinking()- Enable thinking globallydisable_thinking()- Disable thinking globally
Response Object
response.content- The answerresponse.thinking- AI's thought processresponse.tool_calls- Tools that were calledresponse.tool_results- Tool execution results
Parameters
tools=None- List of Python functionsauto_execute=True- Auto-run tools (default)auto_execute=False- Raw tool calls only
🛡️ Model Compatibility
The SDK automatically handles different model capabilities:
# Works with any model - features auto-disabled if unsupported
client = OllamaChatClient(model_name="gemma2:2b") # No tool/thinking support
client.enable_thinking() # Will be ignored if not supported
tools = [add_numbers]
# This still works! Falls back to normal chat
response = client.chat("What is 15 + 27?", tools=tools)
# → "15 + 27 equals 42" (calculated by model, no tools used)
Supported Models:
- ✅ Modern models (e.g.,
qwen3:8b) - Full features - ✅ Tool-only models (e.g.,
llama3:8b) - Tools but no thinking - ✅ Thinking-only models - Thinking but no tools
- ✅ Basic models (e.g.,
gemma2:2b) - Normal chat only
Graceful Degradation:
- Unsupported features are automatically disabled
- No errors or exceptions thrown
- Always provides a response
Advanced Usage
For more control, you can use the lower-level API:
from qv_ollama_sdk import Conversation, OllamaConversationService, ModelParameters
# Create a conversation
conversation = Conversation(model_name="qwen3:8b")
conversation.add_system_message("You are a helpful assistant.")
conversation.add_user_message("What is the capital of France?")
# Generate a response with specific parameters including thinking
service = OllamaConversationService()
parameters = ModelParameters(temperature=0.7, num_ctx=2048, think=True)
response = service.generate_response(conversation, parameters)
print(f"Thinking: {response.thinking}")
print(f"Answer: {response.content}")
Metadata
Release files for qv-ollama-sdk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| qv_ollama_sdk-1.0.0.tar.gz | 16.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qv_ollama_sdk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.2 kB
Release files / qv_ollama_sdk-1.0.0.tar.gz
| Download URL | qv_ollama_sdk-1.0.0.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d932e656990abd3188f2ced580340368e2aa3a8f13ab67f2ecefc68b5ada6a8f
|
|
BLAKE2b-256 checksum How to use checksums |
9e104e2a991fdd5c34ea8d2997134778048e134435863d180bdb4285da687089
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.0
|
Release files / qv_ollama_sdk-1.0.0-py3-none-any.whl
| Download URL | qv_ollama_sdk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af6510ff54789346d83e6a7a05bfa2a63624f0f6534acac14ea9f7efa516a968
|
|
BLAKE2b-256 checksum How to use checksums |
fa55ce17b84d23b9be5371247c5727d66bab9faf19f4e974a47b787053634edb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.0
|
Security for qv-ollama-sdk 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.