14
14
from ramalama .config import CONFIG
15
15
from ramalama .console import EMOJI , should_colorize
16
16
from ramalama .engine import dry_run , stop_container
17
+ from ramalama .logger import logger
17
18
18
19
19
20
def res (response , color ):
@@ -107,12 +108,13 @@ def _make_request_data(self):
107
108
"Content-Type" : "application/json" ,
108
109
}
109
110
110
- if self .args . api_key :
111
+ if getattr ( self .args , " api_key" , None ) :
111
112
if len (self .args .api_key ) < 20 :
112
113
print ("Warning: Provided API key is invalid." )
113
114
114
115
headers ["Authorization" ] = f"Bearer { self .args .api_key } "
115
116
117
+ logger .debug ("Request: URL=%s, Data=%s, Headers=%s" , self .url , json_data , headers )
116
118
request = urllib .request .Request (self .url , data = json_data , headers = headers , method = "POST" )
117
119
118
120
return request
@@ -148,7 +150,7 @@ def _req(self):
148
150
return None
149
151
150
152
def kills (self ):
151
- if self .args . pid2kill :
153
+ if getattr ( self .args , " pid2kill" , None ) :
152
154
os .kill (self .args .pid2kill , signal .SIGINT )
153
155
os .kill (self .args .pid2kill , signal .SIGTERM )
154
156
os .kill (self .args .pid2kill , signal .SIGKILL )
@@ -186,7 +188,7 @@ def chat(args):
186
188
prompt = dry_run (args .ARGS )
187
189
print (f"\n ramalama chat --color { args .color } --prefix \" { args .prefix } \" --url { args .url } { prompt } " )
188
190
return
189
- if hasattr (args , "keepalive" ) and args . keepalive :
191
+ if getattr (args , "keepalive" , False ) :
190
192
signal .signal (signal .SIGALRM , alarm_handler )
191
193
signal .alarm (convert_to_seconds (args .keepalive ))
192
194
@@ -195,7 +197,8 @@ def chat(args):
195
197
if shell .handle_args ():
196
198
return
197
199
shell .loop ()
198
- except TimeoutException :
200
+ except TimeoutException as e :
201
+ logger .debug (f"Timeout Exception: { e } " )
199
202
# Handle the timeout, e.g., print a message and exit gracefully
200
203
print ("" )
201
204
pass
0 commit comments