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

Uploaded Source

Built Distribution

tensorzero-2024.11.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tensorzero-2024.11.2.tar.gz
Algorithm Hash digest
SHA256 daaee93c989c5a5b1091910ebb174f00658fe36b2df02f1460d6d79a5e01f60f
MD5 aa8156c2c02cf523bd8a4edc2ef39b86
BLAKE2b-256 483d386582d788d0251778a7de782a8c062e3609354155aae40a3d57c88572f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2024.11.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ac2f1993c3efceb835f327224d7f54708334597ad4b6ccb6db7fc28821d4f572
MD5 099c11081a0316a803780c5130f5194b
BLAKE2b-256 0d37a4bbda6142d3f0b0f605b262cb09d9a37ad053b8c18f2c9824f842cc60c5

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