Google (Gemini) provider for Metorial
Project description
metorial-google
Google (Gemini) provider integration for Metorial.
Installation
pip install metorial-google
# or
uv add metorial-google
# or
poetry add metorial-google
Features
- 🤖 Gemini Integration: Full support for Gemini Pro, Gemini Flash, and other Google AI models
- 📡 Session Management: Automatic tool lifecycle handling
- 🔄 Format Conversion: Converts Metorial tools to Google function declaration format
- ⚡ Async Support: Full async/await support
Supported Models
All Google Gemini models that support function calling:
gemini-1.5-pro: Most capable Gemini model with 2M context windowgemini-1.5-flash: Fast and efficient Gemini modelgemini-pro: Standard Gemini Pro modelgemini-pro-vision: Gemini Pro with vision capabilities
Usage
Quick Start (Recommended)
import asyncio
import google.generativeai as genai
from metorial import Metorial
async def main():
# Initialize clients
metorial = Metorial(api_key="...your-metorial-api-key...") # async by default
genai.configure(api_key="...your-google-api-key...")
google_client = genai.GenerativeModel('gemini-pro')
# One-liner chat with automatic session management
response = await metorial.run(
"What are the latest commits in the metorial/websocket-explorer repository?",
"...your-mcp-server-deployment-id...", # can also be list
google_client,
model="gemini-pro",
max_iterations=25
)
print("Response:", response)
asyncio.run(main())
Streaming Chat
import asyncio
import google.generativeai as genai
from metorial import Metorial
from metorial.types import StreamEventType
async def streaming_example():
# Initialize clients
metorial = Metorial(api_key="...your-metorial-api-key...")
genai.configure(api_key="...your-google-api-key...")
google_client = genai.GenerativeModel('gemini-pro')
# Streaming chat with real-time responses
async def stream_action(session):
messages = [
{"role": "user", "content": "Explain quantum computing"}
]
async for event in metorial.stream(
google_client, session, messages,
model="gemini-pro",
max_iterations=25
):
if event.type == StreamEventType.CONTENT:
print(f"🤖 {event.content}", end="", flush=True)
elif event.type == StreamEventType.TOOL_CALL:
print(f"\n🔧 Executing {len(event.tool_calls)} tool(s)...")
elif event.type == StreamEventType.COMPLETE:
print(f"\n✅ Complete!")
await metorial.with_session("...your-server-deployment-id...", stream_action)
asyncio.run(streaming_example())
Advanced Usage with Session Management
import asyncio
import google.generativeai as genai
from metorial import Metorial
from metorial_google import MetorialGoogleSession
async def main():
# Initialize clients
metorial = Metorial(api_key="...your-metorial-api-key...")
genai.configure(api_key="...your-google-api-key...")
# Create session with your server deployments
async with metorial.session(["...your-server-deployment-id..."]) as session:
# Create Google-specific wrapper
google_session = MetorialGoogleSession(session.tool_manager)
model = genai.GenerativeModel(
model_name="gemini-pro",
tools=google_session.tools
)
response = model.generate_content("What are the latest commits?")
# Handle function calls if present
if response.candidates[0].content.parts:
function_calls = [
part.function_call for part in response.candidates[0].content.parts
if hasattr(part, 'function_call') and part.function_call
]
if function_calls:
tool_response = await google_session.call_tools(function_calls)
# Continue conversation with tool_response
asyncio.run(main())
Using Convenience Functions
from metorial_google import build_google_tools, call_google_tools
async def example_with_functions():
# Get tools in Google format
tools = build_google_tools(tool_manager)
# Call tools from Google response
response = await call_google_tools(tool_manager, function_calls)
API Reference
MetorialGoogleSession
Main session class for Google integration.
session = MetorialGoogleSession(tool_manager)
Properties:
tools: List of tools in Google function declaration format
Methods:
async call_tools(function_calls): Execute function calls and return user content
build_google_tools(tool_mgr)
Build Google-compatible tool definitions.
Returns: List of tool definitions in Google format
call_google_tools(tool_mgr, function_calls)
Execute function calls from Google response.
Returns: User content with function responses
Tool Format
Tools are converted to Google's function declaration format:
[{
"function_declarations": [
{
"name": "tool_name",
"description": "Tool description",
"parameters": {
"type": "object",
"properties": {...},
"required": [...]
}
}
]
}]
Error Handling
try:
response = await google_session.call_tools(function_calls)
except Exception as e:
print(f"Tool execution failed: {e}")
Tool errors are returned as error objects in the response format.
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_google-1.0.1.tar.gz.
File metadata
- Download URL: metorial_google-1.0.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a2312873fef3f368e0b94e3b97da032a4b19bee2de873a2bf068a22b3eb4251
|
|
| MD5 |
02a785d52bc39e76ff863c43d24307f5
|
|
| BLAKE2b-256 |
e5e19b6ca07466ec1cf8193f54b280a61d51817418c5b691ec5c0da805db27df
|
Provenance
The following attestation bundles were made for metorial_google-1.0.1.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_google-1.0.1.tar.gz -
Subject digest:
6a2312873fef3f368e0b94e3b97da032a4b19bee2de873a2bf068a22b3eb4251 - Sigstore transparency entry: 586714428
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@27ab480ef6432cafec222d823932d253350d54f5 -
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@27ab480ef6432cafec222d823932d253350d54f5 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file metorial_google-1.0.1-py3-none-any.whl.
File metadata
- Download URL: metorial_google-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d661d7ee52b41489e99a28d9f9a95f4515b01fb0fcc1234515f47044c0a7932f
|
|
| MD5 |
fd87e0618ef47a2dd4c9911f6c1e4b6f
|
|
| BLAKE2b-256 |
d54eeb08330a2002d08ae5a090f5453247e19ab78819683dc5aa566a175c4121
|
Provenance
The following attestation bundles were made for metorial_google-1.0.1-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_google-1.0.1-py3-none-any.whl -
Subject digest:
d661d7ee52b41489e99a28d9f9a95f4515b01fb0fcc1234515f47044c0a7932f - Sigstore transparency entry: 586714435
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@27ab480ef6432cafec222d823932d253350d54f5 -
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@27ab480ef6432cafec222d823932d253350d54f5 -
Trigger Event:
workflow_dispatch
-
Statement type: