Base Module
Core utilities for the irouter package.
get_all_models
Get all available models from the Openrouter API:
from irouter.base import get_all_models
# Get model slugs for initializing LLMs
models = get_all_models()
print(models[:3]) # ['openai/gpt-4o', 'anthropic/claude-3.5-sonnet', ...]
# Get human-readable model names
names = get_all_models(slug=False)
print(names[:3]) # ['GPT-4o', 'Claude 3.5 Sonnet', ...]
history_to_markdown
Convert chat history to readable markdown:
detect_content_type
Detect what content is passed. The possible values are:
- "text" if the item is a non-string or doesn't belong to any of the other categories.
Images:
-
"image_url" if item is a URL and ends with a supported image extension.
-
"local_image" if item is a local file path and ends with a supported image extension.
PDFs: 4. "pdf_url" if item is a URL and ends with a PDF extension.
- "local_pdf" if item is a local file path and ends with a PDF extension.
Audio:
- "audio" if item is a local file path and ends with a supported audio extension.
from irouter.base import detect_content_type
# Image URL detection
detect_content_type("https://example.com/image.jpg") # "image_url"
# Local image detection
detect_content_type("./photo.png") # "local_image" (if file exists)
# Text detection
detect_content_type("Hello world") # "text"
encode_base64
Encode local images to base64 for API requests: