Quickstart Guideο
This guide will help you get started with Ollama Toolkit in minutesβfollowing Eidosian principles of efficiency and elegance.
π Installationο
Install from PyPI with a single command:
pip install ollama-toolkit
π Verify Installationο
Ensure everything is working correctly:
from ollama_toolkit import OllamaClient, __version__
# Print version
print(f"Ollama Toolkit version: {__version__}")
# Initialize client
client = OllamaClient()
# Check Ollama connection
try:
version = client.get_version()
print(f"Connected to Ollama {version['version']}!")
except Exception as e:
print(f"Connection failed: {e}")
π¬ Generate Textο
Hereβs a minimal example to generate text:
from ollama_toolkit import OllamaClient
# Initialize client
client = OllamaClient()
# Generate text with the default model
response = client.generate(
model="llama2",
prompt="Explain what APIs are in simple terms.",
stream=False
)
print(response["response"])
π Complete Exampleο
This example showcases automatic installation, model listing, and text generation:
from ollama_toolkit import OllamaClient
from ollama_toolkit.utils.common import ensure_ollama_running
# Ensure Ollama is running (will attempt to install if not found)
is_running, message = ensure_ollama_running()
if not is_running:
print(f"Error: {message}")
exit(1)
print(f"Ollama status: {message}")
# Initialize client
client = OllamaClient()
# List models
models = client.list_models()
model_names = [model["name"] for model in models.get("models", [])]
if not model_names:
print("No models available. Pulling a small model...")
client.pull_model("llama2")
models = client.list_models()
model_names = [model["name"] for model in models.get("models", [])]
# Generate text
if model_names:
model = model_names[0]
print(f"Using model: {model}")
response = client.generate(
model=model,
prompt="What are three key principles of good API design?",
stream=False
)
print(f"\nResponse: {response['response']}")
π Next Stepsο
Dive into detailed examples
Learn about the API reference
Explore chat completion and embeddings