Skip to content

Commit 9b923e6

Browse files
committed
test azure fine tune job create
1 parent 02736ac commit 9b923e6

File tree

3 files changed

+51
-38
lines changed

3 files changed

+51
-38
lines changed

litellm/files/main.py

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async def afile_delete(
198198

199199
def file_delete(
200200
file_id: str,
201-
custom_llm_provider: Literal["openai"] = "openai",
201+
custom_llm_provider: Literal["openai", "azure"] = "openai",
202202
extra_headers: Optional[Dict[str, str]] = None,
203203
extra_body: Optional[Dict[str, str]] = None,
204204
**kwargs,
@@ -210,6 +210,22 @@ def file_delete(
210210
"""
211211
try:
212212
optional_params = GenericLiteLLMParams(**kwargs)
213+
### TIMEOUT LOGIC ###
214+
timeout = optional_params.timeout or kwargs.get("request_timeout", 600) or 600
215+
# set timeout for 10 minutes by default
216+
217+
if (
218+
timeout is not None
219+
and isinstance(timeout, httpx.Timeout)
220+
and supports_httpx_timeout(custom_llm_provider) == False
221+
):
222+
read_timeout = timeout.read or 600
223+
timeout = read_timeout # default 10 min timeout
224+
elif timeout is not None and not isinstance(timeout, httpx.Timeout):
225+
timeout = float(timeout) # type: ignore
226+
elif timeout is None:
227+
timeout = 600.0
228+
_is_async = kwargs.pop("is_async", False) is True
213229
if custom_llm_provider == "openai":
214230
# for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there
215231
api_base = (
@@ -231,34 +247,46 @@ def file_delete(
231247
or litellm.openai_key
232248
or os.getenv("OPENAI_API_KEY")
233249
)
234-
### TIMEOUT LOGIC ###
235-
timeout = (
236-
optional_params.timeout or kwargs.get("request_timeout", 600) or 600
250+
response = openai_files_instance.delete_file(
251+
file_id=file_id,
252+
_is_async=_is_async,
253+
api_base=api_base,
254+
api_key=api_key,
255+
timeout=timeout,
256+
max_retries=optional_params.max_retries,
257+
organization=organization,
237258
)
238-
# set timeout for 10 minutes by default
259+
elif custom_llm_provider == "azure":
260+
api_base = optional_params.api_base or litellm.api_base or get_secret("AZURE_API_BASE") # type: ignore
261+
api_version = (
262+
optional_params.api_version
263+
or litellm.api_version
264+
or get_secret("AZURE_API_VERSION")
265+
) # type: ignore
239266

240-
if (
241-
timeout is not None
242-
and isinstance(timeout, httpx.Timeout)
243-
and supports_httpx_timeout(custom_llm_provider) == False
244-
):
245-
read_timeout = timeout.read or 600
246-
timeout = read_timeout # default 10 min timeout
247-
elif timeout is not None and not isinstance(timeout, httpx.Timeout):
248-
timeout = float(timeout) # type: ignore
249-
elif timeout is None:
250-
timeout = 600.0
267+
api_key = (
268+
optional_params.api_key
269+
or litellm.api_key
270+
or litellm.azure_key
271+
or get_secret("AZURE_OPENAI_API_KEY")
272+
or get_secret("AZURE_API_KEY")
273+
) # type: ignore
251274

252-
_is_async = kwargs.pop("is_async", False) is True
275+
extra_body = optional_params.get("extra_body", {})
276+
azure_ad_token: Optional[str] = None
277+
if extra_body is not None:
278+
azure_ad_token = extra_body.pop("azure_ad_token", None)
279+
else:
280+
azure_ad_token = get_secret("AZURE_AD_TOKEN") # type: ignore
253281

254-
response = openai_files_instance.delete_file(
255-
file_id=file_id,
282+
response = azure_files_instance.delete_file(
256283
_is_async=_is_async,
257284
api_base=api_base,
258285
api_key=api_key,
286+
api_version=api_version,
259287
timeout=timeout,
260288
max_retries=optional_params.max_retries,
261-
organization=organization,
289+
file_id=file_id,
262290
)
263291
else:
264292
raise litellm.exceptions.BadRequestError(

litellm/llms/files_apis/azure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def delete_file(
223223
api_key: Optional[str],
224224
timeout: Union[float, httpx.Timeout],
225225
max_retries: Optional[int],
226-
organization: Optional[str],
226+
organization: Optional[str] = None,
227227
api_version: Optional[str] = None,
228228
client: Optional[Union[AzureOpenAI, AsyncAzureOpenAI]] = None,
229229
):

litellm/tests/test_fine_tuning_api.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,11 @@ async def test_azure_create_fine_tune_jobs_async():
122122
_current_dir = os.path.dirname(os.path.abspath(__file__))
123123
file_path = os.path.join(_current_dir, file_name)
124124

125-
file_obj = await litellm.acreate_file(
126-
file=open(file_path, "rb"),
127-
purpose="fine-tune",
128-
custom_llm_provider="azure",
129-
api_key=os.getenv("AZURE_SWEDEN_API_KEY"),
130-
api_base="https://my-endpoint-sweden-berri992.openai.azure.com/",
131-
)
132-
print("Response from creating file=", file_obj)
133-
134-
await asyncio.sleep(5)
125+
file_id = "file-5e4b20ecbd724182b9964f3cd2ab7212"
135126

136127
create_fine_tuning_response = await litellm.acreate_fine_tuning_job(
137128
model="gpt-35-turbo-1106",
138-
training_file=file_obj.id,
129+
training_file=file_id,
139130
custom_llm_provider="azure",
140131
api_key=os.getenv("AZURE_SWEDEN_API_KEY"),
141132
api_base="https://my-endpoint-sweden-berri992.openai.azure.com/",
@@ -156,12 +147,6 @@ async def test_azure_create_fine_tune_jobs_async():
156147
)
157148
print("response from litellm.list_fine_tuning_jobs=", ft_jobs)
158149

159-
# # delete file
160-
161-
# await litellm.afile_delete(
162-
# file_id=file_obj.id,
163-
# )
164-
165150
# cancel ft job
166151
response = await litellm.acancel_fine_tuning_job(
167152
fine_tuning_job_id=create_fine_tuning_response.id,

0 commit comments

Comments
 (0)