1414import httpx
1515
1616import litellm
17- from litellm import client
17+ from litellm import client , get_secret
18+ from litellm .llms .files_apis .azure import AzureOpenAIFilesAPI
1819from litellm .llms .openai import FileDeleted , FileObject , OpenAIFilesAPI
1920from litellm .types .llms .openai import (
2021 Batch ,
2829
2930####### ENVIRONMENT VARIABLES ###################
3031openai_files_instance = OpenAIFilesAPI ()
32+ azure_files_instance = AzureOpenAIFilesAPI ()
3133#################################################
3234
3335
@@ -402,7 +404,7 @@ def file_list(
402404async def acreate_file (
403405 file : FileTypes ,
404406 purpose : Literal ["assistants" , "batch" , "fine-tune" ],
405- custom_llm_provider : Literal ["openai" ] = "openai" ,
407+ custom_llm_provider : Literal ["openai" , "azure" ] = "openai" ,
406408 extra_headers : Optional [Dict [str , str ]] = None ,
407409 extra_body : Optional [Dict [str , str ]] = None ,
408410 ** kwargs ,
@@ -455,7 +457,31 @@ def create_file(
455457 LiteLLM Equivalent of POST: POST https://api.openai.com/v1/files
456458 """
457459 try :
460+ _is_async = kwargs .pop ("acreate_file" , False ) is True
458461 optional_params = GenericLiteLLMParams (** kwargs )
462+
463+ ### TIMEOUT LOGIC ###
464+ timeout = optional_params .timeout or kwargs .get ("request_timeout" , 600 ) or 600
465+ # set timeout for 10 minutes by default
466+
467+ if (
468+ timeout is not None
469+ and isinstance (timeout , httpx .Timeout )
470+ and supports_httpx_timeout (custom_llm_provider ) == False
471+ ):
472+ read_timeout = timeout .read or 600
473+ timeout = read_timeout # default 10 min timeout
474+ elif timeout is not None and not isinstance (timeout , httpx .Timeout ):
475+ timeout = float (timeout ) # type: ignore
476+ elif timeout is None :
477+ timeout = 600.0
478+
479+ _create_file_request = CreateFileRequest (
480+ file = file ,
481+ purpose = purpose ,
482+ extra_headers = extra_headers ,
483+ extra_body = extra_body ,
484+ )
459485 if custom_llm_provider == "openai" :
460486 # for deepinfra/perplexity/anyscale/groq we check in get_llm_provider and pass in the api base from there
461487 api_base = (
@@ -477,32 +503,6 @@ def create_file(
477503 or litellm .openai_key
478504 or os .getenv ("OPENAI_API_KEY" )
479505 )
480- ### TIMEOUT LOGIC ###
481- timeout = (
482- optional_params .timeout or kwargs .get ("request_timeout" , 600 ) or 600
483- )
484- # set timeout for 10 minutes by default
485-
486- if (
487- timeout is not None
488- and isinstance (timeout , httpx .Timeout )
489- and supports_httpx_timeout (custom_llm_provider ) == False
490- ):
491- read_timeout = timeout .read or 600
492- timeout = read_timeout # default 10 min timeout
493- elif timeout is not None and not isinstance (timeout , httpx .Timeout ):
494- timeout = float (timeout ) # type: ignore
495- elif timeout is None :
496- timeout = 600.0
497-
498- _create_file_request = CreateFileRequest (
499- file = file ,
500- purpose = purpose ,
501- extra_headers = extra_headers ,
502- extra_body = extra_body ,
503- )
504-
505- _is_async = kwargs .pop ("acreate_file" , False ) is True
506506
507507 response = openai_files_instance .create_file (
508508 _is_async = _is_async ,
@@ -513,6 +513,38 @@ def create_file(
513513 organization = organization ,
514514 create_file_data = _create_file_request ,
515515 )
516+ elif custom_llm_provider == "azure" :
517+ api_base = optional_params .api_base or litellm .api_base or get_secret ("AZURE_API_BASE" ) # type: ignore
518+ api_version = (
519+ optional_params .api_version
520+ or litellm .api_version
521+ or get_secret ("AZURE_API_VERSION" )
522+ ) # type: ignore
523+
524+ api_key = (
525+ optional_params .api_key
526+ or litellm .api_key
527+ or litellm .azure_key
528+ or get_secret ("AZURE_OPENAI_API_KEY" )
529+ or get_secret ("AZURE_API_KEY" )
530+ ) # type: ignore
531+
532+ extra_body = optional_params .get ("extra_body" , {})
533+ azure_ad_token : Optional [str ] = None
534+ if extra_body is not None :
535+ azure_ad_token = extra_body .pop ("azure_ad_token" , None )
536+ else :
537+ azure_ad_token = get_secret ("AZURE_AD_TOKEN" ) # type: ignore
538+
539+ response = azure_files_instance .create_file (
540+ _is_async = _is_async ,
541+ api_base = api_base ,
542+ api_key = api_key ,
543+ api_version = api_version ,
544+ timeout = timeout ,
545+ max_retries = optional_params .max_retries ,
546+ create_file_data = _create_file_request ,
547+ )
516548 else :
517549 raise litellm .exceptions .BadRequestError (
518550 message = "LiteLLM doesn't support {} for 'create_batch'. Only 'openai' is supported." .format (
0 commit comments