Skip to main content

Python client for WeyCP API - Multi-provider AI chat completions (Local/OpenAI/Anthropic)

Project description

WeyCP Python Client

PyPI version Python 3.8+ License: MIT

The official Python client for WeyCP API chat completions created by Weycop.


🚀 Features

  • Multi-Provider Support – Use local models (Ollama), OpenAI, and Anthropic models.
  • Familiar API Interface – Easy-to-use chat completions API.
  • Auto-Detection – Automatically detects provider based on model name.
  • Sync & Async support – Use synchronous or asynchronous clients.
  • Built-in error handling – Comprehensive exception handling.
  • Usage tracking – Monitor token usage and costs across providers.
  • Type hints – Full type annotation support.
  • High performance – Optimized for concurrent requests.

📦 Installation

pip install weycop

⚡ Quick Start

Synchronous Client

from weycop import WeycopClient

# Initialize client
client = WeycopClient(api_key="your-api-key")

# Simple chat with local model
response = client.chat(
    message="Hello, how are you?",
    model="qwen3:4b-instruct",
    system_prompt="You are a helpful assistant"
)
print(response)

Multi-Provider Usage

from weycop import WeycopClient, Message

client = WeycopClient(api_key="your-api-key")

# Local models (free)
local_response = client.chat_local(
    model="qwen3:4b-instruct",
    messages=[Message("user", "Hello from local model!")]
)

# OpenAI models (requires OPENAI_API_KEY in server)
openai_response = client.chat_openai(
    model="gpt-4o",
    messages=[Message("user", "Hello from OpenAI!")]
)

# Anthropic models (requires ANTHROPIC_API_KEY in server)
anthropic_response = client.chat_anthropic(
    model="claude-3-5-sonnet-20241022",
    messages=[Message("user", "Hello from Anthropic!")]
)

# Auto-detection (provider detected from model name)
auto_response = client.chat_completions_create(
    model="gpt-4o",  # Automatically detected as "openai"
    messages=[Message("user", "Auto-detected provider!")]
)

Asynchronous Client

import asyncio
from weycop import AsyncWeycopClient

async def main():
    async with AsyncWeycopClient(api_key="your-api-key") as client:
        # Use any provider asynchronously
        response = await client.chat_local(
            model="qwen3:8b",
            messages=[Message("user", "What is machine learning?")]
        )
        print(response.choices[0].message.content)

asyncio.run(main())

🧠 Supported Models

Local Models (Free)

  • qwen3:4b-instruct – Fast, efficient model for general conversations (4GB VRAM)
  • qwen3:8b – Advanced model with extended context (8.5GB VRAM)

OpenAI Models (Pay-per-token)

  • gpt-3.5-turbo – Fast and affordable ($0.0005/$0.0015 per 1K tokens)
  • gpt-4o – Advanced reasoning and analysis ($0.0025/$0.01 per 1K tokens)
  • gpt-4o-mini – Lightweight and fast ($0.00015/$0.0006 per 1K tokens)
  • gpt-4 – Premium model for complex tasks ($0.03/$0.06 per 1K tokens)

Anthropic Models (Pay-per-token)

  • claude-3-5-sonnet-20241022 – Most intelligent model ($0.003/$0.015 per 1K tokens)
  • claude-3-5-haiku-20241022 – Fastest model ($0.00025/$0.00125 per 1K tokens)
  • claude-3-opus-20240229 – Most powerful model ($0.015/$0.075 per 1K tokens)

🔍 Model Information

# Get available models by provider
models = client.get_available_models()
print(models)
# Output: {
#   "local": ["qwen3:4b-instruct", "qwen3:8b"],
#   "openai": ["gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini"],
#   "anthropic": ["claude-3-5-sonnet-20241022", ...]
# }

# Get detailed model information
model_info = client.get_model_info("gpt-4o")
print(f"Provider: {model_info.provider}")
print(f"Context: {model_info.context_length} tokens")
print(f"Cost: ${model_info.cost_per_1k_input_tokens}/1K input tokens")

🛡️ Error Handling

from weycop import WeycopClient, AuthenticationError, RateLimitError, APIError

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

try:
    # Try different providers
    response = client.chat_local("Hello", model="qwen3:4b-instruct")
    print(response.choices[0].message.content)
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limit exceeded")
except APIError as e:
    print(f"API error: {e}")

🔄 Examples

Provider-Specific Usage

from weycop import Message

# Explicit provider specification
completion = client.chat_completions_create(
    model="gpt-4o",
    provider="openai",  # Optional - auto-detected if omitted
    messages=[
        Message("system", "You are a helpful assistant"),
        Message("user", "Explain quantum computing")
    ],
    max_tokens=200
)

System Prompts

from weycop import Message

completion = client.chat_completions_create(
    model="qwen3:8b",
    messages=[
        Message("system", "You are a SQL expert. Only respond with SQL code."),
        Message("user", "Get all users created in the last 30 days")
    ]
)

Multi-turn Conversation

messages = [
    Message("system", "You are a helpful math tutor."),
    Message("user", "What is 15 + 27?"),
]

completion = client.chat_completions_create(model="qwen3:4b-instruct", messages=messages)
assistant_response = completion.choices[0].message.content
messages.append(Message("assistant", assistant_response))

messages.append(Message("user", "Now multiply that by 3"))
completion = client.chat_completions_create(model="qwen3:4b-instruct", messages=messages)
print(completion.choices[0].message.content)

Cost Optimization

# Free local models for development/testing
dev_response = client.chat_local(
    model="qwen3:4b-instruct", 
    messages=[Message("user", "Test message")]
)

# Cost-effective cloud models for production
prod_response = client.chat_openai(
    model="gpt-4o-mini",  # Most affordable OpenAI model
    messages=[Message("user", "Production query")]
)

# Premium models for complex tasks
complex_response = client.chat_anthropic(
    model="claude-3-5-sonnet-20241022",
    messages=[Message("user", "Complex analysis task")]
)

Context Management

with WeycopClient(api_key="your-key") as client:
    response = client.chat("Hello!")
    print(response)
# Client is automatically closed

🚀 Migration from v1.x

If you're upgrading from v1.x, your existing code continues to work:

# v1.x code (still works)
response = client.chat_completions_create(
    model="qwen3:4b-instruct",
    messages=[{"role": "user", "content": "Hello"}]
)

# v2.x additions (new capabilities)
response = client.chat_local(  # Provider-specific methods
    model="qwen3:4b-instruct",
    messages=[{"role": "user", "content": "Hello"}]
)


Support


📜 License

MIT License - see LICENSE file for details.

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

weycop-2.1.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

weycop-2.1.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file weycop-2.1.1.tar.gz.

File metadata

  • Download URL: weycop-2.1.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for weycop-2.1.1.tar.gz
Algorithm Hash digest
SHA256 0cc96924ac1dfc56372fc6e66cee4248bbead166ccd1ebe17171a4d314635062
MD5 5846a1ec6dbd97a7de5e8fe23b355896
BLAKE2b-256 d195a0530fa45addf682874d0b3ba9b3c7d94a0eccde7d512908f194c3579c16

See more details on using hashes here.

File details

Details for the file weycop-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: weycop-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for weycop-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 83e0f03efb3403dbb5148a55abc33f0d9aec60683ca62317a659a8d0de66cd8e
MD5 1e913f9f83a100a74408e034feb49284
BLAKE2b-256 339216f4cb7397ef28e5e83a939f436e57eeab7561e9e835ddd4f2410b1de7e9

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