Skip to content

Commit

Permalink
Update python examples for openai v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White committed Dec 1, 2023
1 parent 9438222 commit 61c49b0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
5 changes: 3 additions & 2 deletions Python/openai-manual/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import dotenv
from autoblocks.tracer import AutoblocksTracer
from autoblocks.vendor.openai import serialize_completion
from openai import OpenAI

dotenv.load_dotenv(".env")
Expand Down Expand Up @@ -41,12 +42,12 @@ def main():
tracer.send_event("ai.request", span_id=span_id, properties=params)
try:
start_time = time.time()
openai_response = client.chat.completions.create(**params)
completion = client.chat.completions.create(**params)
tracer.send_event(
"ai.response",
span_id=span_id,
properties=dict(
response=openai_response,
response=serialize_completion(completion),
latency=(time.time() - start_time) * 1000,
),
)
Expand Down
8 changes: 4 additions & 4 deletions Python/openai-manual/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/openai-manual/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9"
openai = "^1.0.0"
autoblocksai = "^0.0.14"
autoblocksai = "^0.0.17"
python-dotenv = "^1.0.0"
7 changes: 4 additions & 3 deletions Python/pytest-replays/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import dotenv
from autoblocks.tracer import AutoblocksTracer
from autoblocks.vendor.openai import serialize_completion
from openai import OpenAI

dotenv.load_dotenv(".env")
Expand Down Expand Up @@ -48,16 +49,16 @@ def run(content: str, trace_id: Optional[str] = None):

try:
start_time = time.time()
response = client.chat.completions.create(**params)
completion = client.chat.completions.create(**params)
tracer.send_event(
"ai.response",
span_id=span_id,
properties=dict(
response=response,
response=serialize_completion(completion),
latency_ms=(time.time() - start_time) * 1000,
),
)
return response.choices[0].message
return completion.choices[0].message
except Exception as error:
tracer.send_event(
"ai.error",
Expand Down
8 changes: 4 additions & 4 deletions Python/pytest-replays/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/pytest-replays/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9"
openai = "^1.0.0"
autoblocksai = "^0.0.14"
autoblocksai = "^0.0.17"
python-dotenv = "^1.0.0"
pytest = "^7.4.3"
wrapt = "^1.15.0"

0 comments on commit 61c49b0

Please sign in to comment.