Python SDK for CMDOP LLM Service - OpenAI-compatible API for 200+ AI models
Project description
CMDOP LLM Python SDK
Python SDK for CMDOP LLM Service - OpenAI-compatible API for 200+ AI models.
Installation
pip install cmdop-llm
Quick Start
from cmdop_llm import CmdopLLM
client = CmdopLLM(api_key="your-api-key")
response = client.chat.completions.create(
model="anthropic/claude-3.5-sonnet",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
Features
- Drop-in OpenAI replacement - Same API, different models
- 200+ Models - GPT-4, Claude, Llama, Mistral, Gemini via single endpoint
- Streaming - Real-time token streaming
- Vision & OCR - Image analysis and text extraction
- Image Generation - FLUX, DALL-E and other models
- Async Support - Full async/await support
Environment Variables
export CMDOP_API_KEY="your-api-key"
export CMDOP_BASE_URL="https://llm.cmdop.com" # Optional, default
Usage Examples
Chat Completion
from cmdop_llm import CmdopLLM
client = CmdopLLM()
response = client.chat.completions.create(
model="openai/gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing."}
],
temperature=0.7,
max_tokens=1000,
)
print(response.choices[0].message.content)
Streaming
stream = client.chat.completions.create(
model="anthropic/claude-3.5-sonnet",
messages=[{"role": "user", "content": "Write a poem."}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
Vision Analysis
result = client.vision.analyze(
image_url="https://example.com/image.jpg",
prompt="Describe this image"
)
print(result.description)
print(result.extracted_text)
OCR Text Extraction
result = client.ocr.extract(
image_url="https://example.com/document.png"
)
print(result.text)
Image Generation
response = client.images.generate(
model="black-forest-labs/FLUX.1-schnell",
prompt="A futuristic cityscape",
size="1024x1024",
)
print(response.data[0].url)
Async Usage
import asyncio
from cmdop_llm import AsyncCmdopLLM
async def main():
client = AsyncCmdopLLM()
response = await client.chat.completions.create(
model="openai/gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
asyncio.run(main())
Available Models
Access 200+ models including:
- OpenAI: gpt-4o, gpt-4o-mini, gpt-4-turbo
- Anthropic: claude-3.5-sonnet, claude-3-opus, claude-3-haiku
- Google: gemini-pro, gemini-1.5-pro
- Meta: llama-3.1-405b, llama-3.1-70b
- Mistral: mistral-large, mixtral-8x22b
- Image: FLUX.1-schnell, FLUX.1-pro, stable-diffusion-xl
Use model format: provider/model-name (e.g., openai/gpt-4o)
API Reference
CmdopLLM
CmdopLLM(
api_key: str = None, # From CMDOP_API_KEY env if not set
base_url: str = None, # Default: https://llm.cmdop.com
timeout: float = None, # Request timeout
max_retries: int = 2, # Retry count
)
Resources
client.chat.completions- Chat completions (OpenAI compatible)client.images- Image generation (OpenAI compatible)client.models- List available modelsclient.vision- Vision analysis (CMDOP specific)client.ocr- OCR extraction (CMDOP specific)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cmdop_llm-0.1.0.tar.gz
(8.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
cmdop_llm-0.1.0-py3-none-any.whl
(12.6 kB
view details)
File details
Details for the file cmdop_llm-0.1.0.tar.gz.
File metadata
- Download URL: cmdop_llm-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eec0e6acca5daf3da788943ed7ab2c6c0cdd3ed5b74725c502e6439643325d56
|
|
| MD5 |
882060140ab725ca5d6bb20109645e38
|
|
| BLAKE2b-256 |
d23bd5e58a3b1749bbd899a460d0623ef40dc183e436e033e3df025605b67daa
|
File details
Details for the file cmdop_llm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cmdop_llm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efbef8d928b618c85680583f02392f3fc9a0110ce6fc038dd5e6c76e2b9f1991
|
|
| MD5 |
6529c1d12627dad0dd786de6334f8908
|
|
| BLAKE2b-256 |
f12163d06fddaf1cf2d0155a5051040fc4ebef341a5c6610df9a9c8b1100819e
|