@@ -463,26 +463,24 @@ async def get_upload_url(self, file_name, file_size, use_case="multimodal"):
463463 return "" , ""
464464
465465 async def upload (self , upload_url , file_content , mime_type ):
466- headers = self .base_headers .copy ()
467- headers .update (
468- {
469- 'accept' : 'application/json, text/plain, */*' ,
470- 'content-type' : mime_type ,
471- 'x-ms-blob-type' : 'BlockBlob' ,
472- 'x-ms-version' : '2020-04-08' ,
473- }
474- )
475- headers .pop ('authorization' , None )
476- headers .pop ('oai-device-id' , None )
477- headers .pop ('oai-language' , None )
478- try :
479- r = await self .s .put (upload_url , headers = headers , data = file_content , timeout = 120 )
480- if r .status_code == 201 :
481- return True
482- else :
483- raise HTTPException (status_code = r .status_code , detail = r .text )
484- except Exception as e :
485- logger .error (f"Failed to upload file: { e } " )
466+ for i in range (3 ):
467+ try :
468+ headers = self .base_headers .copy ()
469+ headers .update ({
470+ 'accept' : 'application/json, text/plain, */*' ,
471+ 'content-type' : mime_type ,
472+ 'x-ms-blob-type' : 'BlockBlob' ,
473+ 'x-ms-version' : '2020-04-08' ,
474+ })
475+ r = await self .s .put (upload_url , headers = headers , data = file_content , timeout = 120 )
476+ if r .status_code == 201 :
477+ return True
478+ else :
479+ raise HTTPException (status_code = r .status_code , detail = r .text )
480+ except Exception as e :
481+ logger .error (f"Failed to upload file: { e } " )
482+ else :
483+ logger .error (f"Failed to upload file after 3 attempts" )
486484 return False
487485
488486 async def upload_file (self , file_content , mime_type ):
0 commit comments