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
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
Release history Release notifications | RSS feed
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.38.tar.gz
(20.2 kB
view hashes)
Built Distribution
Close
Hashes for autoblocksai-0.0.38-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c3b1edcd2a4edf458a36d0020e119b195c4c406f9d5cb1b54dd1b17640cf754 |
|
MD5 | c37cfcfe0773926bafb3ed2013098967 |
|
BLAKE2b-256 | 2518b33b40b94bd88dc52f364b164484823bc07a5cd4e2aa4f7cd1b5296f26b0 |