Together AI provider for Metorial
Project description
metorial-togetherai
Together AI provider integration for Metorial - enables using Metorial tools with Together AI's language models through OpenAI-compatible function calling.
Installation
pip install metorial-togetherai
# or
uv add metorial-togetherai
# or
poetry add metorial-togetherai
Features
- 🤖 Together AI Integration: Full support for Llama, Mixtral, and other Together AI models
- 🛠️ Function Calling: OpenAI-compatible function calling support
- 📡 Session Management: Automatic tool lifecycle handling
- 🔄 Format Conversion: Converts Metorial tools to OpenAI function format
- ⚡ Async Support: Full async/await support
Usage
Basic Usage
import asyncio
from openai import OpenAI
from metorial import Metorial
from metorial_togetherai import MetorialTogetherAISession
async def main():
# Initialize clients
metorial = Metorial(api_key="your-metorial-api-key")
# Together AI uses OpenAI-compatible client
together_client = OpenAI(
api_key="your-together-api-key",
base_url="https://api.together.xyz/v1"
)
# Create session with your server deployments
async with metorial.session(["your-server-deployment-id"]) as session:
# Create Together AI-specific wrapper
together_session = MetorialTogetherAISession(session.tool_manager)
messages = [
{"role": "user", "content": "Help me with this task"}
]
response = together_client.chat.completions.create(
model="meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
messages=messages,
tools=together_session.tools
)
# Handle tool calls
tool_calls = response.choices[0].message.tool_calls
if tool_calls:
tool_responses = await together_session.call_tools(tool_calls)
# Add to conversation
messages.append({
"role": "assistant",
"tool_calls": tool_calls
})
messages.extend(tool_responses)
# Continue conversation...
asyncio.run(main())
Using Convenience Functions
from metorial_togetherai import build_togetherai_tools, call_togetherai_tools
async def example_with_functions():
# Get tools in Together AI format
tools = build_togetherai_tools(tool_manager)
# Call tools from Together AI response
tool_messages = await call_togetherai_tools(tool_manager, tool_calls)
API Reference
MetorialTogetherAISession
Main session class for Together AI integration.
session = MetorialTogetherAISession(tool_manager)
Properties:
tools: List of tools in OpenAI-compatible format
Methods:
async call_tools(tool_calls): Execute tool calls and return tool messages
build_togetherai_tools(tool_mgr)
Build Together AI-compatible tool definitions.
Returns: List of tool definitions in OpenAI format
call_togetherai_tools(tool_mgr, tool_calls)
Execute tool calls from Together AI response.
Returns: List of tool messages
Tool Format
Tools are converted to OpenAI-compatible format (without strict mode):
{
"type": "function",
"function": {
"name": "tool_name",
"description": "Tool description",
"parameters": {
"type": "object",
"properties": {...},
"required": [...]
}
}
}
Together AI API Configuration
Together AI uses the OpenAI-compatible API format. Configure your client like this:
from openai import OpenAI
client = OpenAI(
api_key="your-together-api-key",
base_url="https://api.together.xyz/v1"
)
Supported Models
Popular models available through Together AI:
meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo: Llama 3.1 70Bmeta-llama/Meta-Llama-3.1-8B-Instruct-Turbo: Llama 3.1 8Bmistralai/Mixtral-8x7B-Instruct-v0.1: Mixtral 8x7BNousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO: Nous Hermes 2- And many more...
Error Handling
try:
tool_messages = await together_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-openai-compatible>=1.0.0metorial-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_togetherai-1.0.0rc1.tar.gz.
File metadata
- Download URL: metorial_togetherai-1.0.0rc1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7685cd9714cae9b4a48d567fc6603bd56b03db113fdcb7f95e12f27160b64ad7
|
|
| MD5 |
17d457163c60dc04e90ed71afe0385ee
|
|
| BLAKE2b-256 |
275521aa58dc631ce11c1f19479c52c456cd81d6b254edc5248fb5b882e69880
|
Provenance
The following attestation bundles were made for metorial_togetherai-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_togetherai-1.0.0rc1.tar.gz -
Subject digest:
7685cd9714cae9b4a48d567fc6603bd56b03db113fdcb7f95e12f27160b64ad7 - Sigstore transparency entry: 314605070
- 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_togetherai-1.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: metorial_togetherai-1.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 4.5 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 |
6f38e9aa79433a09536bd48b8f9196ea7a18d100cc314c53ca2ca8452edf90cd
|
|
| MD5 |
3cb79c017e7eb0a50e9defd6cf21d28d
|
|
| BLAKE2b-256 |
1123a7c9cbc8f5f7af390988954347f3f36e736ea635a560f0b3d7667a862040
|
Provenance
The following attestation bundles were made for metorial_togetherai-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_togetherai-1.0.0rc1-py3-none-any.whl -
Subject digest:
6f38e9aa79433a09536bd48b8f9196ea7a18d100cc314c53ca2ca8452edf90cd - Sigstore transparency entry: 314605092
- 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: