OpenAI-compatible provider base for Metorial
Project description
metorial-openai-compatible
Base package for OpenAI-compatible provider integrations for Metorial. This package provides shared functionality for providers that use OpenAI's function calling format.
Installation
pip install metorial-openai-compatible
# or
uv add metorial-openai-compatible
# or
poetry add metorial-openai-compatible
Features
- 🔧 OpenAI Format: Standard OpenAI function calling format
- ✅ Strict Mode: Configurable strict parameter validation
- 📡 Session Management: Automatic tool lifecycle handling
- 🔄 Format Conversion: Converts Metorial tools to OpenAI function format
- ⚡ Async Support: Full async/await support
- 🏗️ Base Class: Foundation for provider-specific implementations
Usage
Direct Usage
import asyncio
from metorial import Metorial
from metorial_openai_compatible import MetorialOpenAICompatibleSession
async def main():
# Initialize Metorial
metorial = Metorial(api_key="your-metorial-api-key")
# Create session with your server deployments
async with metorial.session(["your-server-deployment-id"]) as session:
# Create OpenAI-compatible wrapper
openai_session = MetorialOpenAICompatibleSession(
session.tool_manager,
with_strict=True # Enable strict mode
)
# Use with any OpenAI-compatible client
tools = openai_session.tools
# Handle tool calls from response
tool_responses = await openai_session.call_tools(tool_calls)
asyncio.run(main())
As Base Class
This package is primarily used as a base for provider-specific packages:
from metorial_openai_compatible import MetorialOpenAICompatibleSession
class MyProviderSession(MetorialOpenAICompatibleSession):
def __init__(self, tool_mgr):
# Configure strict mode based on provider capabilities
super().__init__(tool_mgr, with_strict=False)
Using Convenience Functions
from metorial_openai_compatible import build_openai_compatible_tools, call_openai_compatible_tools
async def example_with_functions():
# Get tools in OpenAI format
tools = build_openai_compatible_tools(tool_manager, with_strict=True)
# Call tools from OpenAI-compatible response
tool_messages = await call_openai_compatible_tools(tool_manager, tool_calls)
API Reference
MetorialOpenAICompatibleSession
Main session class for OpenAI-compatible integration.
session = MetorialOpenAICompatibleSession(tool_manager, with_strict=False)
Parameters:
tool_manager: Metorial tool manager instancewith_strict: Enable strict parameter validation (default: False)
Properties:
tools: List of tools in OpenAI function calling format
Methods:
async call_tools(tool_calls): Execute tool calls and return tool messages
build_openai_compatible_tools(tool_mgr, with_strict=False)
Build OpenAI-compatible tool definitions.
Parameters:
tool_mgr: Tool manager instancewith_strict: Enable strict mode (default: False)
Returns: List of tool definitions in OpenAI format
call_openai_compatible_tools(tool_mgr, tool_calls)
Execute tool calls from OpenAI-compatible response.
Returns: List of tool messages
Tool Format
Tools are converted to OpenAI's function calling format:
{
"type": "function",
"function": {
"name": "tool_name",
"description": "Tool description",
"parameters": {
"type": "object",
"properties": {...},
"required": [...]
},
"strict": True # Only if with_strict=True
}
}
Strict Mode
When with_strict=True, the strict field is added to function definitions for providers that support strict parameter validation (like OpenAI and XAI).
Provider Implementations
This package serves as the base for:
- metorial-xai: XAI (Grok) with strict mode enabled
- metorial-deepseek: DeepSeek without strict mode
- metorial-togetherai: Together AI without strict mode
Error Handling
try:
tool_messages = await session.call_tools(tool_calls)
except Exception as e:
print(f"Tool execution failed: {e}")
Tool errors are returned as tool messages with error content.
Dependencies
metorial-mcp-session>=1.0.0typing-extensions>=4.0.0
License
MIT License - see LICENSE file for details.
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
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
File details
Details for the file metorial_openai_compatible-1.0.0rc1.tar.gz.
File metadata
- Download URL: metorial_openai_compatible-1.0.0rc1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
641bf918e90e9ed1b91fbbd929d8d766a862734f12ca4554446581b8815f7d1a
|
|
| MD5 |
d8cef8e81bd19ec55ed1cd9429b49609
|
|
| BLAKE2b-256 |
6054f6e9b903bc3c187607dc44bc5bcd6c3c05655d1d36bd57aa38fb1fa6e2f8
|
Provenance
The following attestation bundles were made for metorial_openai_compatible-1.0.0rc1.tar.gz:
Publisher:
release.yml on metorial/metorial-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metorial_openai_compatible-1.0.0rc1.tar.gz -
Subject digest:
641bf918e90e9ed1b91fbbd929d8d766a862734f12ca4554446581b8815f7d1a - Sigstore transparency entry: 314605107
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@5d2656e3ae691da7c73c8f7c95b7a1c6737a8cd6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/metorial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5d2656e3ae691da7c73c8f7c95b7a1c6737a8cd6 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file metorial_openai_compatible-1.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: metorial_openai_compatible-1.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acaaa0815d71047869d48a2ac5ec4031dddbf7d5f4b84201ceee97fa5aeb14e5
|
|
| MD5 |
48fcaeaa9ce0b2b9bc410cf7bb2fecbd
|
|
| BLAKE2b-256 |
a7bafd8e672ce4450e766654b66798d3f45e86a30867f1aed1c6d3d41d3791e3
|
Provenance
The following attestation bundles were made for metorial_openai_compatible-1.0.0rc1-py3-none-any.whl:
Publisher:
release.yml on metorial/metorial-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metorial_openai_compatible-1.0.0rc1-py3-none-any.whl -
Subject digest:
acaaa0815d71047869d48a2ac5ec4031dddbf7d5f4b84201ceee97fa5aeb14e5 - Sigstore transparency entry: 314605124
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@5d2656e3ae691da7c73c8f7c95b7a1c6737a8cd6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/metorial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5d2656e3ae691da7c73c8f7c95b7a1c6737a8cd6 -
Trigger Event:
workflow_dispatch
-
Statement type: