Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test fix openai batches and files

Ishaan Jaff0bdebe36d8bd
diff --git a/tests/batches_tests/test_openai_batches_and_files.py b/tests/batches_tests/test_openai_batches_and_files.py
index 8465df78d8d..57825bd0eaf 100644
--- a/tests/batches_tests/test_openai_batches_and_files.py
+++ b/tests/batches_tests/test_openai_batches_and_files.py
@@ -170,6 +170,69 @@ class TestCustomLogger(CustomLogger):
self.standard_logging_object = kwargs["standard_logging_object"]
+def cleanup_azure_files():
+ """
+ Delete all files for Azure - helper for when we run out of Azure Files Quota
+ """
+ azure_files = litellm.file_list(
+ custom_llm_provider="azure",
+ api_key=os.getenv("AZURE_FT_API_KEY"),
+ api_base=os.getenv("AZURE_FT_API_BASE"),
+ )
+ print("azure_files=", azure_files)
+ for _file in azure_files:
+ print("deleting file=", _file)
+ delete_file_response = litellm.file_delete(
+ file_id=_file.id,
+ custom_llm_provider="azure",
+ api_key=os.getenv("AZURE_FT_API_KEY"),
+ api_base=os.getenv("AZURE_FT_API_BASE"),
+ )
+ print("delete_file_response=", delete_file_response)
+ assert delete_file_response.id == _file.id
+
+
+def cleanup_azure_ft_models():
+ """
+ Test CLEANUP: Delete all existing fine tuning jobs for Azure
+ """
+ try:
+ from openai import AzureOpenAI
+ import requests
+
+ client = AzureOpenAI(
+ api_key=os.getenv("AZURE_FT_API_KEY"),
+ azure_endpoint=os.getenv("AZURE_FT_API_BASE"),
+ api_version=os.getenv("AZURE_API_VERSION"),
+ )
+
+ _list_ft_jobs = client.fine_tuning.jobs.list()
+ print("_list_ft_jobs=", _list_ft_jobs)
+
+ # delete all ft jobs make post request to this
+ # Delete all fine-tuning jobs
+ for job in _list_ft_jobs:
+ try:
+ endpoint = os.getenv("AZURE_FT_API_BASE").rstrip("/")
+ url = f"{endpoint}/openai/fine_tuning/jobs/{job.id}?api-version=2024-10-21"
+ print("url=", url)
+
+ headers = {
+ "api-key": os.getenv("AZURE_FT_API_KEY"),
+ "Content-Type": "application/json",
+ }
+
+ response = requests.delete(url, headers=headers)
+ print(f"Deleting job {job.id}: Status {response.status_code}")
+ if response.status_code != 204:
+ print(f"Error deleting job {job.id}: {response.text}")
+
+ except Exception as e:
+ print(f"Error deleting job {job.id}: {str(e)}")
+ except Exception as e:
+ print(f"Error on cleanup_azure_ft_models: {str(e)}")
+
+
@pytest.mark.parametrize("provider", ["openai"])
@pytest.mark.asyncio()
@pytest.mark.flaky(retries=3, delay=1)
@@ -304,69 +367,6 @@ async def test_async_create_batch(provider):
cleanup_azure_ft_models()
-def cleanup_azure_files():
- """
- Delete all files for Azure - helper for when we run out of Azure Files Quota
- """
- azure_files = litellm.file_list(
- custom_llm_provider="azure",
- api_key=os.getenv("AZURE_FT_API_KEY"),
- api_base=os.getenv("AZURE_FT_API_BASE"),
- )
- print("azure_files=", azure_files)
- for _file in azure_files:
- print("deleting file=", _file)
- delete_file_response = litellm.file_delete(
- file_id=_file.id,
- custom_llm_provider="azure",
- api_key=os.getenv("AZURE_FT_API_KEY"),
- api_base=os.getenv("AZURE_FT_API_BASE"),
- )
- print("delete_file_response=", delete_file_response)
- assert delete_file_response.id == _file.id
-
-
-def cleanup_azure_ft_models():
- """
- Test CLEANUP: Delete all existing fine tuning jobs for Azure
- """
- try:
- from openai import AzureOpenAI
- import requests
-
- client = AzureOpenAI(
- api_key=os.getenv("AZURE_FT_API_KEY"),
- azure_endpoint=os.getenv("AZURE_FT_API_BASE"),
- api_version=os.getenv("AZURE_API_VERSION"),
- )
-
- _list_ft_jobs = client.fine_tuning.jobs.list()
- print("_list_ft_jobs=", _list_ft_jobs)
-
- # delete all ft jobs make post request to this
- # Delete all fine-tuning jobs
- for job in _list_ft_jobs:
- try:
- endpoint = os.getenv("AZURE_FT_API_BASE").rstrip("/")
- url = f"{endpoint}/openai/fine_tuning/jobs/{job.id}?api-version=2024-10-21"
- print("url=", url)
-
- headers = {
- "api-key": os.getenv("AZURE_FT_API_KEY"),
- "Content-Type": "application/json",
- }
-
- response = requests.delete(url, headers=headers)
- print(f"Deleting job {job.id}: Status {response.status_code}")
- if response.status_code != 204:
- print(f"Error deleting job {job.id}: {response.text}")
-
- except Exception as e:
- print(f"Error deleting job {job.id}: {str(e)}")
- except Exception as e:
- print(f"Error on cleanup_azure_ft_models: {str(e)}")
-
-
@pytest.mark.asyncio
async def test_avertex_batch_prediction():
load_vertex_ai_credentials()