Model Calling
A unified API for calling multiple LLM providers through a consistent, OpenAI-compatible interface.
Key Features
- 🔄 OpenAI-compatible API: Uses the familiar chat completions format
- ☎️ Multiple Backends: Support for Ollama, vLLM, OpenAI, Anthropic, Cohere, and more
- 🛠️ Function Calling: Unified support for tools/function calling across models
- 📊 Streaming Support: Efficient streaming for all supported models
- 🔧 Runtime Configuration: Adjust model settings without restarting
- 📦 Importable Library: Can be used as a service or imported library
Installation
pip install model-calling
Quick Example
from model_calling.client import SyncModelCallingClient
client = SyncModelCallingClient()
try:
response = client.chat_completion(
model="ollama/mistral-small3.1:24b", # Use any model from any provider
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is machine learning?"}
]
)
print(response["choices"][0]["message"]["content"])
finally:
client.close()
Supported Providers
| Provider | Prefix | Example Models |
|---|---|---|
| Ollama (local) | ollama/ | mistral-small3.1, llama3, qwen |
| vLLM (cluster) | vllm/ | Any model deployed with vLLM |
| OpenAI | openai/ | gpt-4, gpt-3.5-turbo |
| Anthropic | anthropic/ | claude-3-opus, claude-3-sonnet |
| Cohere | cohere/ | command, command-r |
Function Calling
Model Calling provides a consistent interface for function calling (tools) across all supported providers:
import json
from model_calling.client import SyncModelCallingClient
client = SyncModelCallingClient()
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": ["location"]
}
}
}
]
try:
# Initial request with tools
response = client.chat_completion(
model="ollama/mistral-small3.1:24b",
messages=[
{"role": "user", "content": "What's the weather like in Paris?"}
],
tools=tools
)
# Check if function call was requested
message = response["choices"][0]["message"]
if "function_call" in message:
function_name = message["function_call"]["name"]
arguments = json.loads(message["function_call"]["arguments"])
# Call your function with the arguments
weather_data = get_weather(arguments["location"])
# Continue the conversation with the function result
final_response = client.chat_completion(
model="ollama/mistral-small3.1:24b",
messages=[
{"role": "user", "content": "What's the weather like in Paris?"},
{
"role": "assistant",
"content": "",
"function_call": {
"name": "get_weather",
"arguments": json.dumps({"location": "Paris, France"})
}
},
{
"role": "function",
"name": "get_weather",
"content": json.dumps(weather_data)
}
]
)
print(final_response["choices"][0]["message"]["content"])
else:
print(message["content"])
finally:
client.close()
Using as a Service
Model Calling can be run as a service to provide a unified API for all your applications:
# Start the service
python -m model_calling
Then make API calls to the service:
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "ollama/mistral-small3.1:24b",
"messages": [
{"role": "user", "content": "What is machine learning?"}
]
}'
Using Hosted Providers
To use hosted providers like OpenAI and Anthropic, set your API keys in environment variables or a .env file:
# Create a .env file with your API keys
cp .env.example .env
# Edit .env with your API keys
Then you can use the hosted models:
from model_calling.client import SyncModelCallingClient
client = SyncModelCallingClient()
try:
# OpenAI
response = client.chat_completion(
model="openai/gpt-4",
messages=[
{"role": "user", "content": "What is quantum computing?"}
]
)
# Anthropic
response = client.chat_completion(
model="anthropic/claude-3-sonnet-20240229",
messages=[
{"role": "user", "content": "What is quantum computing?"}
]
)
finally:
client.close()
Documentation
For complete documentation, visit the Model Calling Documentation.
Examples
Check out the examples directory for more examples of how to use Model Calling, including:
- Basic chat completions
- Function calling
- Streaming responses
- Building agents
- Working with different providers
License
MIT License
Metadata
Release files for model-calling 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| model_calling-0.1.0.tar.gz | 44.3 kB | Without provenance | Details for model_calling-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| model_calling-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for model_calling-0.1.0-py3-none-any.whl |
Total release size: 96.5 kB
Release files / model_calling-0.1.0.tar.gz
| Download URL | model_calling-0.1.0.tar.gz |
|---|---|
| Size | 44.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17a07816a5527365008c952fa0177efed543168346de7377b7688f1772f20b8e
|
|
BLAKE2b-256 checksum How to use checksums |
5c56fa400b35a3b1ac200425e28eab1f1049b26156736b853314fbb821a8ccda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Release files / model_calling-0.1.0-py3-none-any.whl
| Download URL | model_calling-0.1.0-py3-none-any.whl |
|---|---|
| Size | 52.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0838c0152a18b9bf05eee9e2d52fc55445273d075ccf3bd4dcbb44803437ce08
|
|
BLAKE2b-256 checksum How to use checksums |
54e3410a457fcd3a89a9cb9f072195fff6225f151fdbea0f7538b3a229da8ae2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Security for model-calling 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.