@@ -51,21 +51,21 @@ def load_llm_model(model):
51
51
}
52
52
53
53
# Check for GPU layers
54
- llm = None
54
+ innerllm = None
55
55
gpu_layers = os .getenv ("GPU_LAYERS" )
56
56
if gpu_layers :
57
57
gpu_layers = int (gpu_layers )
58
58
if gpu_layers > 0 :
59
59
print ("GPU Layers: %s" % gpu_layers )
60
- llm = llama_cpp .Llama (model_path = model , n_gpu_layers = gpu_layers )
60
+ innerllm = llama_cpp .Llama (model_path = model , n_gpu_layers = gpu_layers )
61
61
else :
62
- llm = llama_cpp .Llama (model_path = model )
62
+ innerllm = llama_cpp .Llama (model_path = model )
63
63
else :
64
64
# Check if GPU available
65
65
#print("No GPU layers set.")
66
- llm = llama_cpp .Llama (model_path = model )
66
+ innerllm = llama_cpp .Llama (model_path = model )
67
67
68
- return llm
68
+ return innerllm
69
69
70
70
llm = load_llm_model (model )
71
71
@@ -76,8 +76,6 @@ class Tools(AppBase):
76
76
def __init__ (self , redis , logger , console_logger = None ):
77
77
super ().__init__ (redis , logger , console_logger )
78
78
79
- #def run_llm(self, question, model="llama3.2"):
80
- #def run_llm(self, question, model="deepseek-v3"):
81
79
def run_llm (self , input , system_message = "" ):
82
80
global llm
83
81
global model
@@ -88,19 +86,27 @@ def run_llm(self, input, system_message=""):
88
86
self .logger .info ("[DEBUG] Running LLM with model '%s'. To overwrite path, use environment variable MODEL_PATH=<path>" % model )
89
87
90
88
# https://github.com/abetlen/llama-cpp-python
91
- output = llm .create_chat_completion (
92
- max_tokens = 100 ,
93
- messages = [
94
- {
95
- "role" : "system" ,
96
- "content" : system_message ,
97
- },
98
- {
99
- "role" : "user" ,
100
- "content" : input ,
101
- }
102
- ]
103
- )
89
+ try :
90
+ self .logger .info ("[DEBUG] LLM: %s" % llm )
91
+ output = llm .create_chat_completion (
92
+ max_tokens = 100 ,
93
+ messages = [
94
+ {
95
+ "role" : "system" ,
96
+ "content" : system_message ,
97
+ },
98
+ {
99
+ "role" : "user" ,
100
+ "content" : input ,
101
+ }
102
+ ]
103
+ )
104
+ except Exception as e :
105
+ return {
106
+ "success" : False ,
107
+ "reason" : f"Failed to run local LLM. Check logs in this execution for more info: { self .current_execution_id } " ,
108
+ "details" : f"{ e } "
109
+ }
104
110
105
111
self .logger .info ("[DEBUG] LLM output: %s" % output )
106
112
0 commit comments