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.34.tar.gz
(19.6 kB
view hashes)
Built Distribution
Close
Hashes for autoblocksai-0.0.34-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80c6089b1c1bd9339c30238e196308581f38c032cd2f75944a82296ae2b142b8 |
|
MD5 | 664df5a2f0de99dde4b1b7b3528ab68c |
|
BLAKE2b-256 | 2c197d99eee2f93afe99df7c38d4ab29d3258c9ca15f9f8fec41bd1f282250ff |