Skip to main content

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 Distribution

tensorzero-2024.11.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

tensorzero-2024.11.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file tensorzero-2024.11.1.tar.gz.

File metadata

  • Download URL: tensorzero-2024.11.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.25

File hashes

Hashes for tensorzero-2024.11.1.tar.gz
Algorithm Hash digest
SHA256 08821fa3fc87e2b3535c420d199565725091b9be6ae2ccbf052c286291ad35eb
MD5 c46b4f88351880ff549d28c9ceb835e8
BLAKE2b-256 ecfcb9219bb3243b3a4aab201dd7f91ff4ddcda36bf8b9769a161f6c522cb0f7

See more details on using hashes here.

File details

Details for the file tensorzero-2024.11.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tensorzero-2024.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcc57f932e6dbe2779dbc76da643988d870a2d39e121a3eb857f7b4a1ee7550c
MD5 86dcb6f687b7cb918eecbfc6b9d61c50
BLAKE2b-256 495e7d8b9d0a04cb25f0531c4c181e202c6e41fe689f6c53320ee091e6ff4618

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page