From 61c49b02d9c6d35d423713d8b2245725dadc1074 Mon Sep 17 00:00:00 2001 From: Nicole White Date: Fri, 1 Dec 2023 10:44:15 -0500 Subject: [PATCH] Update python examples for openai v1 --- Python/openai-manual/main.py | 5 +++-- Python/openai-manual/poetry.lock | 8 ++++---- Python/openai-manual/pyproject.toml | 2 +- Python/pytest-replays/main.py | 7 ++++--- Python/pytest-replays/poetry.lock | 8 ++++---- Python/pytest-replays/pyproject.toml | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Python/openai-manual/main.py b/Python/openai-manual/main.py index 2edceb1f..c7cf7862 100644 --- a/Python/openai-manual/main.py +++ b/Python/openai-manual/main.py @@ -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") @@ -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, ), ) diff --git a/Python/openai-manual/poetry.lock b/Python/openai-manual/poetry.lock index 0520428c..6f3d7d33 100644 --- a/Python/openai-manual/poetry.lock +++ b/Python/openai-manual/poetry.lock @@ -34,13 +34,13 @@ trio = ["trio (<0.22)"] [[package]] name = "autoblocksai" -version = "0.0.14" +version = "0.0.17" description = "Python client for Autoblocks" optional = false python-versions = ">=3.8.1,<4.0.0" files = [ - {file = "autoblocksai-0.0.14-py3-none-any.whl", hash = "sha256:a95c6ad810caba6f73640090aad9180f4872367bdafa3fe3e91cac3536962aad"}, - {file = "autoblocksai-0.0.14.tar.gz", hash = "sha256:677316e1476a71df3416567a24c4efb4ab63b85ca347c0cb7c8c5637d8d53111"}, + {file = "autoblocksai-0.0.17-py3-none-any.whl", hash = "sha256:00951246f9cc69fcae5dbf2af64a4fb508cd08203142c353555c350496180dae"}, + {file = "autoblocksai-0.0.17.tar.gz", hash = "sha256:9a76b538235644fd7a581d55462d51c33d615de943caa0b4d763f55f781f02f7"}, ] [package.dependencies] @@ -377,4 +377,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "5bf2adc382854d3d21da3204138d44adbb23052098c3a9ba65931eecbbf48cf0" +content-hash = "2706784f88343646ee7186bd61882e0bb83b8d9e491bc87f1880fb405b5f9325" diff --git a/Python/openai-manual/pyproject.toml b/Python/openai-manual/pyproject.toml index 546f4535..2af9c62f 100644 --- a/Python/openai-manual/pyproject.toml +++ b/Python/openai-manual/pyproject.toml @@ -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" diff --git a/Python/pytest-replays/main.py b/Python/pytest-replays/main.py index 95b6f6fb..8fa03304 100644 --- a/Python/pytest-replays/main.py +++ b/Python/pytest-replays/main.py @@ -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") @@ -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", diff --git a/Python/pytest-replays/poetry.lock b/Python/pytest-replays/poetry.lock index 1b18c933..c18b1c87 100644 --- a/Python/pytest-replays/poetry.lock +++ b/Python/pytest-replays/poetry.lock @@ -34,13 +34,13 @@ trio = ["trio (<0.22)"] [[package]] name = "autoblocksai" -version = "0.0.14" +version = "0.0.17" description = "Python client for Autoblocks" optional = false python-versions = ">=3.8.1,<4.0.0" files = [ - {file = "autoblocksai-0.0.14-py3-none-any.whl", hash = "sha256:a95c6ad810caba6f73640090aad9180f4872367bdafa3fe3e91cac3536962aad"}, - {file = "autoblocksai-0.0.14.tar.gz", hash = "sha256:677316e1476a71df3416567a24c4efb4ab63b85ca347c0cb7c8c5637d8d53111"}, + {file = "autoblocksai-0.0.17-py3-none-any.whl", hash = "sha256:00951246f9cc69fcae5dbf2af64a4fb508cd08203142c353555c350496180dae"}, + {file = "autoblocksai-0.0.17.tar.gz", hash = "sha256:9a76b538235644fd7a581d55462d51c33d615de943caa0b4d763f55f781f02f7"}, ] [package.dependencies] @@ -526,4 +526,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "598480de7b04cacde261375a4c3c9fd3a4726d9dd9240254e54d755f629a1ddc" +content-hash = "f62524f84a6e7dfc55c60fc28dc59d3a5fa895501ed6191d9455adccfa015522" diff --git a/Python/pytest-replays/pyproject.toml b/Python/pytest-replays/pyproject.toml index c77b1423..1c209fcf 100644 --- a/Python/pytest-replays/pyproject.toml +++ b/Python/pytest-replays/pyproject.toml @@ -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"