Skip to content

Commit

Permalink
Add random tags to async httpx test.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljin committed Jan 30, 2024
1 parent 03033a2 commit f7bf77e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -55,22 +55,23 @@ 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 = {
"role": "user",
"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)])

0 comments on commit f7bf77e

Please sign in to comment.