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

Uploaded Source

Built Distribution

tensorzero-2024.10.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tensorzero-2024.10.1.tar.gz
Algorithm Hash digest
SHA256 e7e803664608b7fb1adb2eb5606c641fe103bc14bbeaa1a6be9a2d032a6309dd
MD5 9fba3ee10e433951bfbcf842c5819be0
BLAKE2b-256 c9491b04434497650583bd7115ac42dfbeaadde8a4b123f4343d259a8d8463f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2024.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 621730d9faf611b4eee74c33944d0de37ecf76b18dfbd7ade82b81c565f59761
MD5 12341b77c3739746f838f009fb859796
BLAKE2b-256 9e12a9964b73ff612b216cae321ceda9943d2a1bbf8f3ad9eea443b2884aadb3

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