File tree Expand file tree Collapse file tree
lib/galaxy/webapps/galaxy/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,20 +203,27 @@ async def _open_ai_adapter(
203203 try :
204204 client = AsyncOpenAI (** client_kwargs )
205205 except Exception as e :
206- log .debug ("Failed to initialize OpenAI client" , exc_info = e )
206+ log .debug ("Failed to initialize OpenAI client. " , exc_info = e )
207207 return self .create_error ("Failed to initialize AI client." , 500 )
208208
209209 # Connect to ai provider
210210 log .info (f"Proxying to { ai_model } , tokens: { max_tokens } " )
211- response = await client .chat .completions .create (
212- max_tokens = max_tokens ,
213- messages = messages ,
214- model = ai_model ,
215- stream = stream ,
216- temperature = TEMPERATURE ,
217- tools = tools ,
218- top_p = TOP_P ,
219- )
211+ try :
212+ response = await client .chat .completions .create (
213+ max_tokens = max_tokens ,
214+ messages = messages ,
215+ model = ai_model ,
216+ stream = stream ,
217+ temperature = TEMPERATURE ,
218+ tools = tools ,
219+ top_p = TOP_P ,
220+ )
221+ except Exception as e :
222+ log .debug ("Failed to complete OpenAI request." , exc_info = e )
223+ status_code = getattr (e , "status_code" , 500 )
224+ if hasattr (e , "body" ) and isinstance (e .body , dict ):
225+ return JSONResponse (status_code = status_code , content = dict (error = e .body ))
226+ return self .create_error ("Failed to complete OpenAI request." , status_code )
220227
221228 # Parse response
222229 if stream :
You can’t perform that action at this time.
0 commit comments