Skip to main content

A simple SDK for interacting with the Ollama API by automatically creating a conversation (chat history)

Project description

QV Ollama SDK

A simple SDK for interacting with the Ollama API.

Features

  • Simple conversation management
  • Support for synchronous API calls
  • Streaming response support
  • Explicit parameter handling (no unnecessary defaults)
  • User-friendly client interface

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="gemma2:2b",
    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)

# Continue the conversation
response = client.chat("And what is its population?")
print(response)

# 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()

Streaming Responses

from qv_ollama_sdk import OllamaChatClient

client = OllamaChatClient(model_name="gemma2:2b")

# Stream the response
for chunk in client.stream_chat("Explain quantum computing."):
    print(chunk, end="", flush=True)

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="gemma2:2b")
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
service = OllamaConversationService()
parameters = ModelParameters(temperature=0.7, num_ctx=2048)
response = service.generate_response(conversation, parameters)

print(response.content)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qv_ollama_sdk-0.2.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qv_ollama_sdk-0.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file qv_ollama_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: qv_ollama_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for qv_ollama_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e63617bd20bcd3ef240a7ae610468ce91318bcb0f3c8ca4a03948600d1d1c3d6
MD5 0d8e7b6a8f5d5a2c8774c343108dbe36
BLAKE2b-256 0c510a83067f610c1f50a95003482ccf5a534a83176f109a6a5aaaa20d81c2b9

See more details on using hashes here.

File details

Details for the file qv_ollama_sdk-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for qv_ollama_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a0f27c8ddfde327eea43507fc898448cae9797ddb877e11eb1d7370a87600f2
MD5 18039905086e629685491d6b93226f78
BLAKE2b-256 921f7e7c4056c9ebab31ff5e0889ebeb8fa5c6d01f10a8beaeb4c954fdb452c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page