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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for tensorzero-2024.9.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28ef940eaf6c92b894a65b0e6c34c1b83c83902cfb026297726b63b8db9e9243 |
|
MD5 | 413ef05e71b7225ab7385c7bbd53e0ef |
|
BLAKE2b-256 | 8c38e333de06064d0ed176a5c2fe5979c1688afd17e91cbc1ce2cc0e4d4e99c6 |