mistral fix, error text output

frdel committed Dec 6, 2024 at 15:17 UTC 53a46288f9a72928ec902b36625080ad07ebe2a1
4 files changed +35 -17
agent.py
+7 -1
@@ -392,9 +392,15 @@ class Agent:
392 ) # Re-raise the exception to cancel the loop
393 else:
394 # Handling for general exceptions
395 + error_text = errors.error_text(exception)
396 error_message = errors.format_error(exception)
397 PrintStyle(font_color="red", padding=True).print(error_message)
397 - self.context.log.log(type="error", heading="Error", content=error_message)
398 + self.context.log.log(
399 + type="error",
400 + heading="Error",
401 + content=error_message,
402 + kvps={"text": error_text},
403 + )
404 raise HandledException(exception) # Re-raise the exception to kill the loop
405
406 async def get_system_prompt(self, loop_data: LoopData) -> list[str]:
models.py
+1 -1
@@ -252,7 +252,7 @@ def get_google_embedding(
252
253
254 # Mistral models
255 -def get_mistral_chat(
255 +def get_mistralai_chat(
256 model_name: str,
257 api_key=None,
258 temperature=DEFAULT_TEMPERATURE,
python/helpers/errors.py
+26 -14
@@ -2,39 +2,51 @@ import re
2 import traceback
3 import asyncio
4
5 +
6 def handle_error(e: Exception):
7 # if asyncio.CancelledError, re-raise
8 if isinstance(e, asyncio.CancelledError):
9 raise e
9 -
10 +
11 +
12 +def error_text(e: Exception):
13 + return str(e)
14 +
15 +
16 def format_error(e: Exception, start_entries=6, end_entries=4):
17 traceback_text = traceback.format_exc()
18 # Split the traceback into lines
13 - lines = traceback_text.split('\n')
14 -
19 + lines = traceback_text.split("\n")
20 +
21 # Find all "File" lines
16 - file_indices = [i for i, line in enumerate(lines) if line.strip().startswith("File ")]
17 -
22 + file_indices = [
23 + i for i, line in enumerate(lines) if line.strip().startswith("File ")
24 + ]
25 +
26 # If we found at least one "File" line, trim the middle if there are more than start_entries+end_entries lines
27 if len(file_indices) > start_entries + end_entries:
28 start_index = max(0, len(file_indices) - start_entries - end_entries)
21 - trimmed_lines = lines[:file_indices[start_index]] + [
22 - f"\n>>> {len(file_indices) - start_entries - end_entries} stack lines skipped <<<\n"
23 - ] + lines[file_indices[start_index + end_entries]:]
29 + trimmed_lines = (
30 + lines[: file_indices[start_index]]
31 + + [
32 + f"\n>>> {len(file_indices) - start_entries - end_entries} stack lines skipped <<<\n"
33 + ]
34 + + lines[file_indices[start_index + end_entries] :]
35 + )
36 else:
37 # If no "File" lines found, or not enough to trim, just return the original traceback
38 trimmed_lines = lines
27 -
39 +
40 # Find the error message at the end
41 error_message = ""
42 for line in reversed(trimmed_lines):
31 - if re.match(r'\w+Error:', line):
43 + if re.match(r"\w+Error:", line):
44 error_message = line
45 break
34 -
46 +
47 # Combine the trimmed traceback with the error message
36 - result = "Traceback (most recent call last):\n" + '\n'.join(trimmed_lines)
48 + result = "Traceback (most recent call last):\n" + "\n".join(trimmed_lines)
49 if error_message:
50 result += f"\n\n{error_message}"
39 -
40 - return result
\ No newline at end of file
51 +
52 + return result
webui/js/messages.js
+1 -1
@@ -247,7 +247,7 @@ export function drawMessageCodeExe(messageContainer, id, type, heading, content,
247
248 export function drawMessageAgentPlain(classes, messageContainer, id, type, heading, content, temp, kvps = null) {
249 const messageContent = convertImageTags(content); // Convert image tags
250 - _drawMessage(messageContainer, heading, messageContent, temp, false, null, [...classes]);
250 + _drawMessage(messageContainer, heading, messageContent, temp, false, kvps, [...classes]);
251 messageContainer.classList.add('center-container');
252 }
253