From 812dd5e162ddcc5ee00793a48446241382b818e6 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 26 Jul 2024 18:40:10 -0700 Subject: [PATCH] test get batches by id --- tests/test_openai_batches_endpoint.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_openai_batches_endpoint.py b/tests/test_openai_batches_endpoint.py index f996c7e8b..75e3c3f88 100644 --- a/tests/test_openai_batches_endpoint.py +++ b/tests/test_openai_batches_endpoint.py @@ -28,14 +28,37 @@ async def create_batch(session, input_file_id, endpoint, completion_window): return result +async def get_batch_by_id(session, batch_id): + url = f"{BASE_URL}/v1/batches/{batch_id}" + headers = {"Authorization": f"Bearer {API_KEY}"} + + async with session.get(url, headers=headers) as response: + if response.status == 200: + result = await response.json() + return result + else: + print(f"Error: Failed to get batch. Status code: {response.status}") + return None + + @pytest.mark.asyncio -async def test_file_operations(): +async def test_batches_operations(): async with aiohttp.ClientSession() as session: # Test file upload and get file_id file_id = await upload_file(session, purpose="batch") - batch_id = await create_batch(session, file_id, "/v1/chat/completions", "24h") + create_batch_response = await create_batch( + session, file_id, "/v1/chat/completions", "24h" + ) + batch_id = create_batch_response.get("id") assert batch_id is not None + # Test get batch + get_batch_response = await get_batch_by_id(session, batch_id) + print("response from get batch", get_batch_response) + + assert get_batch_response["id"] == batch_id + assert get_batch_response["input_file_id"] == file_id + # Test delete file await delete_file(session, file_id)