From f7bf77e257a49df054a6b1e32641c1d6ed906599 Mon Sep 17 00:00:00 2001 From: Michael Jin Date: Tue, 30 Jan 2024 14:46:59 -0800 Subject: [PATCH] Add random tags to async httpx test. --- tests/test_requests.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index a8c76277..f8d1a210 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1,11 +1,11 @@ import asyncio -import os +import uuid import httpx import pytest import requests_mock -from log10.load import log_sync, log_async, OpenAI +from log10.load import log_sync, log_async, OpenAI, log10_session from log10.llm import LLM, Log10Config @@ -55,7 +55,7 @@ def fake_logging(): @pytest.mark.skip(reason="This is a very simple load test and doesn't need to be run as part of the test suite.") @pytest.mark.asyncio -async def test_log_async_httpx_multiple_calls(respx_mock): +async def test_log_async_httpx_multiple_calls_with_tags(respx_mock): simultaneous_calls = 100 mock_resp = { @@ -63,14 +63,15 @@ async def test_log_async_httpx_multiple_calls(respx_mock): "content": "Say this is a test", } - client = OpenAI() respx_mock.post("https://api.openai.com/v1/chat/completions").mock(return_value=httpx.Response(200, json=mock_resp)) def better_logging(): - completion = client.chat.completions.create(model="gpt-3.5-turbo", messages=[ - {"role": "user", "content": "Say pong"}]) + uuids = [str(uuid.uuid4()) for _ in range(5)] + with log10_session(tags=uuids) as s: + completion = client.chat.completions.create(model="gpt-3.5-turbo", messages=[ + {"role": "user", "content": "Say pong"}]) loop = asyncio.get_event_loop() await asyncio.gather(*[loop.run_in_executor(None, better_logging) for _ in range(simultaneous_calls)])