Skip to content

Commit 951246f

Browse files
committed
Missing options of api_key and pid2kill are causing crashes
Also add debug information to chat. Signed-off-by: Daniel J Walsh <[email protected]>
1 parent dc43419 commit 951246f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ramalama/chat.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ramalama.config import CONFIG
1515
from ramalama.console import EMOJI, should_colorize
1616
from ramalama.engine import dry_run, stop_container
17+
from ramalama.logger import logger
1718

1819

1920
def res(response, color):
@@ -107,12 +108,13 @@ def _make_request_data(self):
107108
"Content-Type": "application/json",
108109
}
109110

110-
if self.args.api_key:
111+
if getattr(self.args, "api_key", None):
111112
if len(self.args.api_key) < 20:
112113
print("Warning: Provided API key is invalid.")
113114

114115
headers["Authorization"] = f"Bearer {self.args.api_key}"
115116

117+
logger.debug("Request: URL=%s, Data=%s, Headers=%s", self.url, json_data, headers)
116118
request = urllib.request.Request(self.url, data=json_data, headers=headers, method="POST")
117119

118120
return request
@@ -148,7 +150,7 @@ def _req(self):
148150
return None
149151

150152
def kills(self):
151-
if self.args.pid2kill:
153+
if getattr(self.args, "pid2kill", None):
152154
os.kill(self.args.pid2kill, signal.SIGINT)
153155
os.kill(self.args.pid2kill, signal.SIGTERM)
154156
os.kill(self.args.pid2kill, signal.SIGKILL)
@@ -186,7 +188,7 @@ def chat(args):
186188
prompt = dry_run(args.ARGS)
187189
print(f"\nramalama chat --color {args.color} --prefix \"{args.prefix}\" --url {args.url} {prompt}")
188190
return
189-
if hasattr(args, "keepalive") and args.keepalive:
191+
if getattr(args, "keepalive", False):
190192
signal.signal(signal.SIGALRM, alarm_handler)
191193
signal.alarm(convert_to_seconds(args.keepalive))
192194

@@ -195,7 +197,8 @@ def chat(args):
195197
if shell.handle_args():
196198
return
197199
shell.loop()
198-
except TimeoutException:
200+
except TimeoutException as e:
201+
logger.debug(f"Timeout Exception: {e}")
199202
# Handle the timeout, e.g., print a message and exit gracefully
200203
print("")
201204
pass

0 commit comments

Comments
 (0)