mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
test_openai_fine_tuning
This commit is contained in:
parent
296013f722
commit
52450e9f61
1 changed files with 41 additions and 37 deletions
|
|
@ -2,6 +2,7 @@ from openai import AsyncOpenAI
|
|||
import os
|
||||
import pytest
|
||||
import asyncio
|
||||
import openai
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -9,54 +10,57 @@ async def test_openai_fine_tuning():
|
|||
"""
|
||||
[PROD Test] e2e tests for /fine_tuning/jobs endpoints
|
||||
"""
|
||||
client = AsyncOpenAI(api_key="sk-1234", base_url="http://0.0.0.0:4000")
|
||||
try:
|
||||
client = AsyncOpenAI(api_key="sk-1234", base_url="http://0.0.0.0:4000")
|
||||
|
||||
file_name = "openai_fine_tuning.jsonl"
|
||||
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
file_path = os.path.join(_current_dir, file_name)
|
||||
file_name = "openai_fine_tuning.jsonl"
|
||||
_current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
file_path = os.path.join(_current_dir, file_name)
|
||||
|
||||
response = await client.files.create(
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
file=open(file_path, "rb"),
|
||||
purpose="fine-tune",
|
||||
)
|
||||
response = await client.files.create(
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
file=open(file_path, "rb"),
|
||||
purpose="fine-tune",
|
||||
)
|
||||
|
||||
print("response from files.create: {}".format(response))
|
||||
print("response from files.create: {}".format(response))
|
||||
|
||||
await asyncio.sleep(5)
|
||||
await asyncio.sleep(5)
|
||||
|
||||
# create fine tuning job
|
||||
# create fine tuning job
|
||||
|
||||
ft_job = await client.fine_tuning.jobs.create(
|
||||
model="gpt-4o-mini-2024-07-18",
|
||||
training_file=response.id,
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
)
|
||||
ft_job = await client.fine_tuning.jobs.create(
|
||||
model="gpt-4o-mini-2024-07-18",
|
||||
training_file=response.id,
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
)
|
||||
|
||||
print("response from ft job={}".format(ft_job))
|
||||
print("response from ft job={}".format(ft_job))
|
||||
|
||||
# response from example endpoint
|
||||
assert ft_job.id is not None
|
||||
# response from example endpoint
|
||||
assert ft_job.id is not None
|
||||
|
||||
# list all fine tuning jobs
|
||||
list_ft_jobs = await client.fine_tuning.jobs.list(
|
||||
extra_query={"custom_llm_provider": "openai"}
|
||||
)
|
||||
# list all fine tuning jobs
|
||||
list_ft_jobs = await client.fine_tuning.jobs.list(
|
||||
extra_query={"custom_llm_provider": "openai"}
|
||||
)
|
||||
|
||||
print("list of ft jobs={}".format(list_ft_jobs))
|
||||
print("list of ft jobs={}".format(list_ft_jobs))
|
||||
|
||||
# cancel specific fine tuning job
|
||||
cancel_ft_job = await client.fine_tuning.jobs.cancel(
|
||||
fine_tuning_job_id=ft_job.id,
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
)
|
||||
# cancel specific fine tuning job
|
||||
cancel_ft_job = await client.fine_tuning.jobs.cancel(
|
||||
fine_tuning_job_id=ft_job.id,
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
)
|
||||
|
||||
print("response from cancel ft job={}".format(cancel_ft_job))
|
||||
print("response from cancel ft job={}".format(cancel_ft_job))
|
||||
|
||||
assert cancel_ft_job.id is not None
|
||||
assert cancel_ft_job.id is not None
|
||||
|
||||
# delete OG file
|
||||
await client.files.delete(
|
||||
file_id=response.id,
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
)
|
||||
# delete OG file
|
||||
await client.files.delete(
|
||||
file_id=response.id,
|
||||
extra_body={"custom_llm_provider": "openai"},
|
||||
)
|
||||
except openai.InternalServerError:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue