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.18.tar.gz
(13.0 kB
view hashes)
Built Distribution
Close
Hashes for autoblocksai-0.0.18-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4b2323b78a45aff78df244b7b03ba8a84e1f0ca05f0ba5dc5f33946dfa29b04 |
|
MD5 | efb0668789fdf65d9b06cd52a2db1fd8 |
|
BLAKE2b-256 | 299da3993e2328c1e95aaef7605694e42fdb832394b3e280b0542f28a51e6f9d |