The Python client for TensorZero
Project description
TensorZero Python Client
Website · Docs · Twitter · Slack · Discord
Quick Start (5min) · Comprehensive Tutorial · Deployment Guide · API Reference · Configuration Reference
The tensorzero
package provides an async Python client for the TensorZero Gateway.
This client allows you to easily make inference requests and assign feedback to them via the gateway.
See our API Reference for more information.
Installation
pip install tensorzero
Basic Usage
Non-Streaming Inference
import asyncio
from tensorzero import AsyncTensorZeroGateway
async def run(topic):
async with AsyncTensorZeroGateway("http://localhost:3000") as client:
result = await client.inference(
function_name="generate_haiku",
input={
"messages": [
{"role": "user", "content": {"topic": topic}},
],
},
)
print(result)
if __name__ == "__main__":
asyncio.run(run("artificial intelligence"))
Streaming Inference
import asyncio
from tensorzero import AsyncTensorZeroGateway
async def run(topic):
async with AsyncTensorZeroGateway("http://localhost:3000") as client:
stream = await client.inference(
function_name="generate_haiku",
input={
"messages": [
{"role": "user", "content": {"topic": topic}},
],
},
stream=True,
)
async for chunk in stream:
print(chunk)
if __name__ == "__main__":
asyncio.run(run("artificial intelligence"))
Feedback
import asyncio
from tensorzero import AsyncTensorZeroGateway
async def run(inference_id):
async with AsyncTensorZeroGateway("http://localhost:3000") as client:
result = await client.feedback(
metric_name="thumbs_up",
inference_id=inference_id,
value=True, # 👍
)
print(result)
if __name__ == "__main__":
asyncio.run(run("00000000-0000-0000-0000-000000000000"))
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
tensorzero-2024.10.0.tar.gz
(12.5 kB
view details)
Built Distribution
File details
Details for the file tensorzero-2024.10.0.tar.gz
.
File metadata
- Download URL: tensorzero-2024.10.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.25
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b49bcb5cd4395444603d66d7015372c9911a382023dde2cba04ad0dbfdbc86df |
|
MD5 | 2151075931f940e63c855fe3d9ee020f |
|
BLAKE2b-256 | 8df61b7008f97b0ee82978106a875a24f066d182e8482210c118e20a879d3fa6 |
File details
Details for the file tensorzero-2024.10.0-py3-none-any.whl
.
File metadata
- Download URL: tensorzero-2024.10.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.25
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 374ca1d002e3f3a7a70453199dc2828dcf713c14757fb0b744864aec116b43be |
|
MD5 | ac61396e761d9e6724bc1e7adbe4e320 |
|
BLAKE2b-256 | 94ec3db4366ae289ca7705133515817d4149c93cdecbf6f8c5536cf3ec4a202d |