11import os
22
33os .environ ["LITELLM_LOCAL_MODEL_COST_MAP" ] = "True"
4+ import sys
5+
46import litellm
57
68litellm .suppress_debug_info = True
@@ -310,17 +312,17 @@ def load(self):
310312
311313 if self .model .startswith ("ollama/" ):
312314 model_name = self .model .replace ("ollama/" , "" )
313- api_base = getattr (self , ' api_base' , None ) or "http://localhost:11434"
315+ api_base = getattr (self , " api_base" , None ) or "http://localhost:11434"
314316 names = []
315317 try :
316318 # List out all downloaded ollama models. Will fail if ollama isn't installed
317319 response = requests .get (f"{ api_base } /api/tags" )
318320 if response .ok :
319321 data = response .json ()
320322 names = [
321- model [' name' ].replace (":latest" , "" )
322- for model in data [' models' ]
323- if ' name' in model and model [' name' ]
323+ model [" name" ].replace (":latest" , "" )
324+ for model in data [" models" ]
325+ if " name" in model and model [" name" ]
324326 ]
325327
326328 except Exception as e :
@@ -337,7 +339,9 @@ def load(self):
337339
338340 # Get context window if not set
339341 if self .context_window == None :
340- response = requests .post (f"{ api_base } /api/show" , json = {"name" : model_name })
342+ response = requests .post (
343+ f"{ api_base } /api/show" , json = {"name" : model_name }
344+ )
341345 model_info = response .json ().get ("model_info" , {})
342346 context_length = None
343347 for key in model_info :
@@ -399,6 +403,9 @@ def fixed_litellm_completions(**params):
399403 try :
400404 yield from litellm .completion (** params )
401405 return # If the completion is successful, exit the function
406+ except KeyboardInterrupt :
407+ print ("Exiting..." )
408+ sys .exit (0 )
402409 except Exception as e :
403410 if attempt == 0 :
404411 # Store the first error
0 commit comments