Skip to main content

Python client for Autoblocks

Project description

📚 Documentation   •   🖥️ Application   •   🏠 Home

Installation

poetry add autoblocksai
pip install autoblocksai

Examples

See our Python examples.

Quickstart

import os
import uuid
import traceback
import time

import openai
from autoblocks.tracer import AutoblocksTracer

openai.api_key = os.environ["OPENAI_API_KEY"]
messages = [
  {
    "role": "system",
    "content": "You are a helpful assistant. You answer questions about a software product named Acme.",
  },
  {
    "role": "user",
    "content": "How do I sign up?",
  },
]
request_params = dict(
  model="gpt-3.5-turbo",
  messages=messages,
  temperature=0.7,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0,
  n=1,
)

tracer = AutoblocksTracer(
  os.environ["AUTOBLOCKS_INGESTION_KEY"],
  # All events sent below will have this trace ID
  trace_id=str(uuid.uuid4()),
  # All events sent below will include this property
  # alongside any other properties set in the send_event call
  properties=dict(
    provider="openai",
  ),
)

tracer.send_event(
  "ai.request",
  properties=request_params,
)

try:
  start_time = time.time()
  response = openai.ChatCompletion.create(**request_params)
  tracer.send_event(
    "ai.response",
    properties=dict(
      response=response,
      latency_ms=(time.time() - start_time) * 1000,
    ),
  )
except Exception as error:
  tracer.send_event(
    "ai.error",
    properties=dict(
      error_message=str(error),
      stacktrace=traceback.format_exc(),
    ),
  )

# Simulate user feedback
tracer.send_event(
  "user.feedback",
  properties=dict(
    feedback="good",
  ),
)

Documentation

See the full documentation.

Issues / Questions

Please open an issue if you encounter any bugs, have any questions, or have any feature requests.

Contributing

See CONTRIBUTING.md.

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

autoblocksai-0.0.21.tar.gz (20.8 kB view hashes)

Uploaded Source

Built Distribution

autoblocksai-0.0.21-py3-none-any.whl (29.4 kB view hashes)

Uploaded Python 3

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