mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
feat FT cancel and LIST endpoints for Azure
This commit is contained in:
parent
c6bff3286c
commit
02736ac8b5
3 changed files with 132 additions and 54 deletions
|
@ -279,6 +279,25 @@ def cancel_fine_tuning_job(
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
optional_params = GenericLiteLLMParams(**kwargs)
|
optional_params = GenericLiteLLMParams(**kwargs)
|
||||||
|
### TIMEOUT LOGIC ###
|
||||||
|
timeout = optional_params.timeout or kwargs.get("request_timeout", 600) or 600
|
||||||
|
# set timeout for 10 minutes by default
|
||||||
|
|
||||||
|
if (
|
||||||
|
timeout is not None
|
||||||
|
and isinstance(timeout, httpx.Timeout)
|
||||||
|
and supports_httpx_timeout(custom_llm_provider) == False
|
||||||
|
):
|
||||||
|
read_timeout = timeout.read or 600
|
||||||
|
timeout = read_timeout # default 10 min timeout
|
||||||
|
elif timeout is not None and not isinstance(timeout, httpx.Timeout):
|
||||||
|
timeout = float(timeout) # type: ignore
|
||||||
|
elif timeout is None:
|
||||||
|
timeout = 600.0
|
||||||
|
|
||||||
|
_is_async = kwargs.pop("acancel_fine_tuning_job", False) is True
|
||||||
|
|
||||||
|
# OpenAI
|
||||||
if custom_llm_provider == "openai":
|
if custom_llm_provider == "openai":
|
||||||
|
|
||||||
# for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there
|
# for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there
|
||||||
|
@ -301,25 +320,6 @@ def cancel_fine_tuning_job(
|
||||||
or litellm.openai_key
|
or litellm.openai_key
|
||||||
or os.getenv("OPENAI_API_KEY")
|
or os.getenv("OPENAI_API_KEY")
|
||||||
)
|
)
|
||||||
### TIMEOUT LOGIC ###
|
|
||||||
timeout = (
|
|
||||||
optional_params.timeout or kwargs.get("request_timeout", 600) or 600
|
|
||||||
)
|
|
||||||
# set timeout for 10 minutes by default
|
|
||||||
|
|
||||||
if (
|
|
||||||
timeout is not None
|
|
||||||
and isinstance(timeout, httpx.Timeout)
|
|
||||||
and supports_httpx_timeout(custom_llm_provider) == False
|
|
||||||
):
|
|
||||||
read_timeout = timeout.read or 600
|
|
||||||
timeout = read_timeout # default 10 min timeout
|
|
||||||
elif timeout is not None and not isinstance(timeout, httpx.Timeout):
|
|
||||||
timeout = float(timeout) # type: ignore
|
|
||||||
elif timeout is None:
|
|
||||||
timeout = 600.0
|
|
||||||
|
|
||||||
_is_async = kwargs.pop("acancel_fine_tuning_job", False) is True
|
|
||||||
|
|
||||||
response = openai_fine_tuning_apis_instance.cancel_fine_tuning_job(
|
response = openai_fine_tuning_apis_instance.cancel_fine_tuning_job(
|
||||||
api_base=api_base,
|
api_base=api_base,
|
||||||
|
@ -330,6 +330,40 @@ def cancel_fine_tuning_job(
|
||||||
max_retries=optional_params.max_retries,
|
max_retries=optional_params.max_retries,
|
||||||
_is_async=_is_async,
|
_is_async=_is_async,
|
||||||
)
|
)
|
||||||
|
# Azure OpenAI
|
||||||
|
elif custom_llm_provider == "azure":
|
||||||
|
api_base = optional_params.api_base or litellm.api_base or get_secret("AZURE_API_BASE") # type: ignore
|
||||||
|
|
||||||
|
api_version = (
|
||||||
|
optional_params.api_version
|
||||||
|
or litellm.api_version
|
||||||
|
or get_secret("AZURE_API_VERSION")
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
|
api_key = (
|
||||||
|
optional_params.api_key
|
||||||
|
or litellm.api_key
|
||||||
|
or litellm.azure_key
|
||||||
|
or get_secret("AZURE_OPENAI_API_KEY")
|
||||||
|
or get_secret("AZURE_API_KEY")
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
|
extra_body = optional_params.get("extra_body", {})
|
||||||
|
azure_ad_token: Optional[str] = None
|
||||||
|
if extra_body is not None:
|
||||||
|
azure_ad_token = extra_body.pop("azure_ad_token", None)
|
||||||
|
else:
|
||||||
|
azure_ad_token = get_secret("AZURE_AD_TOKEN") # type: ignore
|
||||||
|
|
||||||
|
response = azure_fine_tuning_apis_instance.cancel_fine_tuning_job(
|
||||||
|
api_base=api_base,
|
||||||
|
api_key=api_key,
|
||||||
|
api_version=api_version,
|
||||||
|
fine_tuning_job_id=fine_tuning_job_id,
|
||||||
|
timeout=timeout,
|
||||||
|
max_retries=optional_params.max_retries,
|
||||||
|
_is_async=_is_async,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise litellm.exceptions.BadRequestError(
|
raise litellm.exceptions.BadRequestError(
|
||||||
message="LiteLLM doesn't support {} for 'create_batch'. Only 'openai' is supported.".format(
|
message="LiteLLM doesn't support {} for 'create_batch'. Only 'openai' is supported.".format(
|
||||||
|
@ -405,6 +439,25 @@ def list_fine_tuning_jobs(
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
optional_params = GenericLiteLLMParams(**kwargs)
|
optional_params = GenericLiteLLMParams(**kwargs)
|
||||||
|
### TIMEOUT LOGIC ###
|
||||||
|
timeout = optional_params.timeout or kwargs.get("request_timeout", 600) or 600
|
||||||
|
# set timeout for 10 minutes by default
|
||||||
|
|
||||||
|
if (
|
||||||
|
timeout is not None
|
||||||
|
and isinstance(timeout, httpx.Timeout)
|
||||||
|
and supports_httpx_timeout(custom_llm_provider) == False
|
||||||
|
):
|
||||||
|
read_timeout = timeout.read or 600
|
||||||
|
timeout = read_timeout # default 10 min timeout
|
||||||
|
elif timeout is not None and not isinstance(timeout, httpx.Timeout):
|
||||||
|
timeout = float(timeout) # type: ignore
|
||||||
|
elif timeout is None:
|
||||||
|
timeout = 600.0
|
||||||
|
|
||||||
|
_is_async = kwargs.pop("alist_fine_tuning_jobs", False) is True
|
||||||
|
|
||||||
|
# OpenAI
|
||||||
if custom_llm_provider == "openai":
|
if custom_llm_provider == "openai":
|
||||||
|
|
||||||
# for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there
|
# for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there
|
||||||
|
@ -427,25 +480,6 @@ def list_fine_tuning_jobs(
|
||||||
or litellm.openai_key
|
or litellm.openai_key
|
||||||
or os.getenv("OPENAI_API_KEY")
|
or os.getenv("OPENAI_API_KEY")
|
||||||
)
|
)
|
||||||
### TIMEOUT LOGIC ###
|
|
||||||
timeout = (
|
|
||||||
optional_params.timeout or kwargs.get("request_timeout", 600) or 600
|
|
||||||
)
|
|
||||||
# set timeout for 10 minutes by default
|
|
||||||
|
|
||||||
if (
|
|
||||||
timeout is not None
|
|
||||||
and isinstance(timeout, httpx.Timeout)
|
|
||||||
and supports_httpx_timeout(custom_llm_provider) == False
|
|
||||||
):
|
|
||||||
read_timeout = timeout.read or 600
|
|
||||||
timeout = read_timeout # default 10 min timeout
|
|
||||||
elif timeout is not None and not isinstance(timeout, httpx.Timeout):
|
|
||||||
timeout = float(timeout) # type: ignore
|
|
||||||
elif timeout is None:
|
|
||||||
timeout = 600.0
|
|
||||||
|
|
||||||
_is_async = kwargs.pop("alist_fine_tuning_jobs", False) is True
|
|
||||||
|
|
||||||
response = openai_fine_tuning_apis_instance.list_fine_tuning_jobs(
|
response = openai_fine_tuning_apis_instance.list_fine_tuning_jobs(
|
||||||
api_base=api_base,
|
api_base=api_base,
|
||||||
|
@ -457,6 +491,41 @@ def list_fine_tuning_jobs(
|
||||||
max_retries=optional_params.max_retries,
|
max_retries=optional_params.max_retries,
|
||||||
_is_async=_is_async,
|
_is_async=_is_async,
|
||||||
)
|
)
|
||||||
|
# Azure OpenAI
|
||||||
|
elif custom_llm_provider == "azure":
|
||||||
|
api_base = optional_params.api_base or litellm.api_base or get_secret("AZURE_API_BASE") # type: ignore
|
||||||
|
|
||||||
|
api_version = (
|
||||||
|
optional_params.api_version
|
||||||
|
or litellm.api_version
|
||||||
|
or get_secret("AZURE_API_VERSION")
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
|
api_key = (
|
||||||
|
optional_params.api_key
|
||||||
|
or litellm.api_key
|
||||||
|
or litellm.azure_key
|
||||||
|
or get_secret("AZURE_OPENAI_API_KEY")
|
||||||
|
or get_secret("AZURE_API_KEY")
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
|
extra_body = optional_params.get("extra_body", {})
|
||||||
|
azure_ad_token: Optional[str] = None
|
||||||
|
if extra_body is not None:
|
||||||
|
azure_ad_token = extra_body.pop("azure_ad_token", None)
|
||||||
|
else:
|
||||||
|
azure_ad_token = get_secret("AZURE_AD_TOKEN") # type: ignore
|
||||||
|
|
||||||
|
response = azure_fine_tuning_apis_instance.list_fine_tuning_jobs(
|
||||||
|
api_base=api_base,
|
||||||
|
api_key=api_key,
|
||||||
|
api_version=api_version,
|
||||||
|
after=after,
|
||||||
|
limit=limit,
|
||||||
|
timeout=timeout,
|
||||||
|
max_retries=optional_params.max_retries,
|
||||||
|
_is_async=_is_async,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise litellm.exceptions.BadRequestError(
|
raise litellm.exceptions.BadRequestError(
|
||||||
message="LiteLLM doesn't support {} for 'create_batch'. Only 'openai' is supported.".format(
|
message="LiteLLM doesn't support {} for 'create_batch'. Only 'openai' is supported.".format(
|
||||||
|
|
|
@ -91,13 +91,15 @@ class AzureOpenAIFineTuningAPI(BaseLLM):
|
||||||
api_base: Optional[str],
|
api_base: Optional[str],
|
||||||
timeout: Union[float, httpx.Timeout],
|
timeout: Union[float, httpx.Timeout],
|
||||||
max_retries: Optional[int],
|
max_retries: Optional[int],
|
||||||
organization: Optional[str],
|
organization: Optional[str] = None,
|
||||||
|
api_version: Optional[str] = None,
|
||||||
client: Optional[Union[AzureOpenAI, AsyncAzureOpenAI]] = None,
|
client: Optional[Union[AzureOpenAI, AsyncAzureOpenAI]] = None,
|
||||||
):
|
):
|
||||||
openai_client: Optional[Union[AzureOpenAI, AsyncAzureOpenAI]] = (
|
openai_client: Optional[Union[AzureOpenAI, AsyncAzureOpenAI]] = (
|
||||||
get_azure_openai_client(
|
get_azure_openai_client(
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
api_base=api_base,
|
api_base=api_base,
|
||||||
|
api_version=api_version,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
max_retries=max_retries,
|
max_retries=max_retries,
|
||||||
organization=organization,
|
organization=organization,
|
||||||
|
@ -141,8 +143,9 @@ class AzureOpenAIFineTuningAPI(BaseLLM):
|
||||||
api_base: Optional[str],
|
api_base: Optional[str],
|
||||||
timeout: Union[float, httpx.Timeout],
|
timeout: Union[float, httpx.Timeout],
|
||||||
max_retries: Optional[int],
|
max_retries: Optional[int],
|
||||||
organization: Optional[str],
|
organization: Optional[str] = None,
|
||||||
client: Optional[Union[AzureOpenAI, AsyncAzureOpenAI]] = None,
|
client: Optional[Union[AzureOpenAI, AsyncAzureOpenAI]] = None,
|
||||||
|
api_version: Optional[str] = None,
|
||||||
after: Optional[str] = None,
|
after: Optional[str] = None,
|
||||||
limit: Optional[int] = None,
|
limit: Optional[int] = None,
|
||||||
):
|
):
|
||||||
|
@ -150,6 +153,7 @@ class AzureOpenAIFineTuningAPI(BaseLLM):
|
||||||
get_azure_openai_client(
|
get_azure_openai_client(
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
api_base=api_base,
|
api_base=api_base,
|
||||||
|
api_version=api_version,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
max_retries=max_retries,
|
max_retries=max_retries,
|
||||||
organization=organization,
|
organization=organization,
|
||||||
|
@ -175,4 +179,3 @@ class AzureOpenAIFineTuningAPI(BaseLLM):
|
||||||
verbose_logger.debug("list fine tuning job, after= %s, limit= %s", after, limit)
|
verbose_logger.debug("list fine tuning job, after= %s, limit= %s", after, limit)
|
||||||
response = openai_client.fine_tuning.jobs.list(after=after, limit=limit) # type: ignore
|
response = openai_client.fine_tuning.jobs.list(after=after, limit=limit) # type: ignore
|
||||||
return response
|
return response
|
||||||
pass
|
|
||||||
|
|
|
@ -146,11 +146,15 @@ async def test_azure_create_fine_tune_jobs_async():
|
||||||
assert create_fine_tuning_response.id is not None
|
assert create_fine_tuning_response.id is not None
|
||||||
assert create_fine_tuning_response.model == "gpt-35-turbo-1106"
|
assert create_fine_tuning_response.model == "gpt-35-turbo-1106"
|
||||||
|
|
||||||
# # list fine tuning jobs
|
# list fine tuning jobs
|
||||||
# print("listing ft jobs")
|
print("listing ft jobs")
|
||||||
# ft_jobs = await litellm.alist_fine_tuning_jobs(limit=2)
|
ft_jobs = await litellm.alist_fine_tuning_jobs(
|
||||||
# print("response from litellm.list_fine_tuning_jobs=", ft_jobs)
|
limit=2,
|
||||||
# assert len(list(ft_jobs)) > 0
|
custom_llm_provider="azure",
|
||||||
|
api_key=os.getenv("AZURE_SWEDEN_API_KEY"),
|
||||||
|
api_base="https://my-endpoint-sweden-berri992.openai.azure.com/",
|
||||||
|
)
|
||||||
|
print("response from litellm.list_fine_tuning_jobs=", ft_jobs)
|
||||||
|
|
||||||
# # delete file
|
# # delete file
|
||||||
|
|
||||||
|
@ -158,13 +162,15 @@ async def test_azure_create_fine_tune_jobs_async():
|
||||||
# file_id=file_obj.id,
|
# file_id=file_obj.id,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
# # cancel ft job
|
# cancel ft job
|
||||||
# response = await litellm.acancel_fine_tuning_job(
|
response = await litellm.acancel_fine_tuning_job(
|
||||||
# fine_tuning_job_id=create_fine_tuning_response.id,
|
fine_tuning_job_id=create_fine_tuning_response.id,
|
||||||
# )
|
custom_llm_provider="azure",
|
||||||
|
api_key=os.getenv("AZURE_SWEDEN_API_KEY"),
|
||||||
|
api_base="https://my-endpoint-sweden-berri992.openai.azure.com/",
|
||||||
|
)
|
||||||
|
|
||||||
# print("response from litellm.cancel_fine_tuning_job=", response)
|
print("response from litellm.cancel_fine_tuning_job=", response)
|
||||||
|
|
||||||
# assert response.status == "cancelled"
|
assert response.status == "cancelled"
|
||||||
# assert response.id == create_fine_tuning_response.id
|
assert response.id == create_fine_tuning_response.id
|
||||||
# pass
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue