Skip to main content

Python SDK for the Servo backend (routing/classification).

Project description

Servo Python SDK

Python SDK for the Servo backend (routing/classification).

Features

Simple 3-step API - Initialize, send, receive
Full type hints - Type-safe with dataclasses
Conversation management - Built-in chat history handling
Modern Python - Python 3.10+ with type annotations
Minimal dependencies - Uses standard library HTTP client

Installation

pip install servo-sdk

Or install in development mode:

pip install -e .

Quick Start

from servo_sdk import Servo

# 1. Initialize client
client = Servo(
    api_key="your-api-key",
    base_url="http://localhost:8000",
    default_user_id="default_user"
)

# 2. Send request
result = client.send("Who was the first president of the United States?")

# 3. Receive response
print(result.classification.category_id)     # e.g., 'simple' or 'complex'
print(result.target_model)                   # e.g., 'gemma-3-27b-it'
print(result.llm_response)                   # actual LLM response

Usage

Basic Usage

from servo_sdk import Servo

client = Servo(
    api_key="ADAWODWA",
    base_url="http://localhost:8000",         # optional, defaults to localhost:8000
    timeout_s=30.0,                           # optional, defaults to 30.0
    default_user_id="default_user",           # optional, defaults to 'default_user'
)

result = client.send("What is machine learning?")
print(result)

With Conversation Context

from servo_sdk import Servo
from servo_sdk.context import Conversation

client = Servo(api_key="your-key")

# Create a conversation with system prompt
conversation = Conversation(system_prompt="You are a helpful AI assistant.")
conversation.add_user("Hello!")
conversation.add_assistant("Hi there!")

# Send with conversation context
result = client.send("What did we just discuss?", conversation=conversation)

Step-by-Step Processing

# Step 1: Classify the prompt
classification = client.classify(
    "Explain quantum computing",
    user_id=None,        # optional, uses default_user_id
    use_quick=False      # default: False
)

print(classification.category_id)         # e.g., 'simple' or 'complex'
print(classification.category_name)       # e.g., 'Simple' or 'Complex'
print(classification.confidence)          # 0.0 - 1.0
print(classification.requires_chunking)   # boolean

# Step 2: Route to appropriate model
routing = client.route(classification)
print(routing.target_model)  # e.g., 'gemini-2.5-flash'

Health Check & Tiers

# Check backend health
health = client.health()
print(health)

# Get available model tiers
tiers = client.tiers()
print(tiers.tiers)  # {'simple': 'gemma-3-27b-it', 'complex': 'gemini-2.5-flash'}

# Get available categories with full metadata
categories = client.categories()
print(categories.user_id)             # 'default_user'
print(categories.default_category_id) # 'simple'
print(categories.categories)          # list of ClassificationCategory

API Reference

See the full type definitions in servo_sdk/types.py and client methods in servo_sdk/client.py.

Key Types

  • ClassificationResult - Result from classifying a prompt
  • ClassificationCategory - Category metadata with provider and model info
  • CategoriesResponse - User-specific categories configuration
  • ProcessingResult - Complete result including classification, routing, and LLM response
  • TiersResponse - Mapping of category IDs to model IDs

Requirements

  • Python 3.10+ (for union type syntax)

Development

# Install in development mode
pip install -e .

# Run tests
pytest

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

servo_sdk-0.1.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

servo_sdk-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file servo_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: servo_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for servo_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a3b25e75687e1bb50078f34986ec1d7fd1084f548210ce320a4ba3fd3acf6b8
MD5 57cb967f706ee5ccab5e0d9ebc87f826
BLAKE2b-256 d4098cffa73fc9a84288ee833993a5a7104d574dff2fdb74ba6ef7e304755158

See more details on using hashes here.

File details

Details for the file servo_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: servo_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for servo_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c92cdf7c98e77deacab0e24a1a9ae94c0904b81d12e8afe584f7c20e55f377c5
MD5 3a900374c89b3c3f45c3ebed2bbfbdcd
BLAKE2b-256 23ea2d101ace57d851ea94c383fcdf7c178e7ac446493395151e9235579491fc

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