forked from phoenix/litellm-mirror
test - batches endpoint
This commit is contained in:
parent
56ce7e892d
commit
12729ceece
2 changed files with 43 additions and 2 deletions
41
tests/test_openai_batches_endpoint.py
Normal file
41
tests/test_openai_batches_endpoint.py
Normal file
|
@ -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)
|
|
@ -30,11 +30,11 @@ async def test_file_operations():
|
||||||
await delete_file(session, file_id)
|
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"
|
url = f"{BASE_URL}/v1/files"
|
||||||
headers = {"Authorization": f"Bearer {API_KEY}"}
|
headers = {"Authorization": f"Bearer {API_KEY}"}
|
||||||
data = aiohttp.FormData()
|
data = aiohttp.FormData()
|
||||||
data.add_field("purpose", "fine-tune")
|
data.add_field("purpose", purpose)
|
||||||
data.add_field(
|
data.add_field(
|
||||||
"file", b'{"prompt": "Hello", "completion": "Hi"}', filename="mydata.jsonl"
|
"file", b'{"prompt": "Hello", "completion": "Hi"}', filename="mydata.jsonl"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue