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.35.tar.gz
(19.6 kB
view hashes)
Built Distribution
Close
Hashes for autoblocksai-0.0.35-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e2019b367fd826e82b30846b0f6633ebff167f6f8f46c912fb4cc4f7fe1d848 |
|
MD5 | 3f4a3f532a5f3a11dffff99c0ee2b689 |
|
BLAKE2b-256 | 73f60086de81809074cabba01e2762b12f63cc4cbcd77f653ed2b2d5f3f4450e |