1
1
import os
2
2
3
3
os .environ ["LITELLM_LOCAL_MODEL_COST_MAP" ] = "True"
4
+ import sys
5
+
4
6
import litellm
5
7
6
8
litellm .suppress_debug_info = True
@@ -310,17 +312,17 @@ def load(self):
310
312
311
313
if self .model .startswith ("ollama/" ):
312
314
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"
314
316
names = []
315
317
try :
316
318
# List out all downloaded ollama models. Will fail if ollama isn't installed
317
319
response = requests .get (f"{ api_base } /api/tags" )
318
320
if response .ok :
319
321
data = response .json ()
320
322
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" ]
324
326
]
325
327
326
328
except Exception as e :
@@ -337,7 +339,9 @@ def load(self):
337
339
338
340
# Get context window if not set
339
341
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
+ )
341
345
model_info = response .json ().get ("model_info" , {})
342
346
context_length = None
343
347
for key in model_info :
@@ -399,6 +403,9 @@ def fixed_litellm_completions(**params):
399
403
try :
400
404
yield from litellm .completion (** params )
401
405
return # If the completion is successful, exit the function
406
+ except KeyboardInterrupt :
407
+ print ("Exiting..." )
408
+ sys .exit (0 )
402
409
except Exception as e :
403
410
if attempt == 0 :
404
411
# Store the first error
0 commit comments