diff --git a/tests/test_openai_batches_endpoint.py b/tests/test_openai_batches_endpoint.py new file mode 100644 index 000000000..f996c7e8b --- /dev/null +++ b/tests/test_openai_batches_endpoint.py @@ -0,0 +1,41 @@ +# What this tests ? +## Tests /batches endpoints +import pytest +import asyncio +import aiohttp, openai +from openai import OpenAI, AsyncOpenAI +from typing import Optional, List, Union +from test_openai_files_endpoints import upload_file, delete_file + + +BASE_URL = "http://localhost:4000" # Replace with your actual base URL +API_KEY = "sk-1234" # Replace with your actual API key + + +async def create_batch(session, input_file_id, endpoint, completion_window): + url = f"{BASE_URL}/v1/batches" + headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"} + payload = { + "input_file_id": input_file_id, + "endpoint": endpoint, + "completion_window": completion_window, + } + + async with session.post(url, headers=headers, json=payload) as response: + assert response.status == 200, f"Expected status 200, got {response.status}" + result = await response.json() + print(f"Batch creation successful. Batch ID: {result.get('id', 'N/A')}") + return result + + +@pytest.mark.asyncio +async def test_file_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") + assert batch_id is not None + + # Test delete file + await delete_file(session, file_id) diff --git a/tests/test_openai_files_endpoints.py b/tests/test_openai_files_endpoints.py index d3922ab69..1444b8a70 100644 --- a/tests/test_openai_files_endpoints.py +++ b/tests/test_openai_files_endpoints.py @@ -30,11 +30,11 @@ async def test_file_operations(): await delete_file(session, file_id) -async def upload_file(session): +async def upload_file(session, purpose="fine-tune"): url = f"{BASE_URL}/v1/files" headers = {"Authorization": f"Bearer {API_KEY}"} data = aiohttp.FormData() - data.add_field("purpose", "fine-tune") + data.add_field("purpose", purpose) data.add_field( "file", b'{"prompt": "Hello", "completion": "Hi"}', filename="mydata.jsonl" )