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.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: tensorzero-2024.11.0.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.0.tar.gz
Algorithm Hash digest
SHA256 658df78c63c23fc9588f01522d15fc0f7d43f395b3fbf73157997ecfa3f6de9f
MD5 a6aae6ad1ebf2892cdd76e81de98159f
BLAKE2b-256 95f27f0a6c110085b9157e7a4f4a49aa0a7dea679bc3983bd6a213b593425976

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2024.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccdcd7e79866946524b8b27702915d67a9555e769744c1ee967298b6e0e1b8c0
MD5 2fa308644f11638bfafd379a8d83e8ee
BLAKE2b-256 8897fd5dfd0bd15d27ef2c90164a890839074075ed40644c132b49173dff7bea

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