-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
29 lines (23 loc) · 943 Bytes
/
Copy pathbasic_usage.py
File metadata and controls
29 lines (23 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
What: The smallest possible Driftlock integration — wrap the OpenAI client,
make one call, read aggregated cost/token stats. No framework needed.
Requires: OPENAI_API_KEY (makes one real ~$0.00001 call to gpt-4o-mini).
Run: OPENAI_API_KEY=sk-... python examples/basic_usage.py
"""
import json
import os
from driftlock import DriftlockClient, DriftlockConfig
client = DriftlockClient(
api_key=os.environ["OPENAI_API_KEY"],
config=DriftlockConfig(log_json=False), # human-readable logs for the terminal
)
# Identical call signature to openai.OpenAI().chat.completions.create()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "What is 2 + 2?"}],
_dl_endpoint="math_demo",
)
print("\nReply:", response.choices[0].message.content)
# Pull aggregated stats from local SQLite
print("\n--- Stats ---")
print(json.dumps(client.stats(), indent=2))