fix: Update process method return type and handle image attribute correctly; improve error handling

This commit is contained in:
Showdown76 2025-05-19 13:10:46 +02:00
parent 670066100f
commit b881f04acc
2 changed files with 6 additions and 4 deletions

View File

@ -39,7 +39,7 @@ class AIProcessor:
return f"Error executing {name}: {e}" return f"Error executing {name}: {e}"
# -------------------------- main entry -------------------------- # # -------------------------- main entry -------------------------- #
def process(self, prompt: str, img_data: str | bytes | None = None) -> str | list[str | dict]: def process(self, prompt: str, img_data: str | bytes | None = None) -> list[str | dict]:
outputs = [] # type: list[str | dict] outputs = [] # type: list[str | dict]
reexec = True reexec = True
nextsteps = "" nextsteps = ""
@ -68,7 +68,7 @@ class AIProcessor:
outputs.append(r) if r else None outputs.append(r) if r else None
# Make sure the two last messages from user has an image, but set disable_image to True for the others # Make sure the two last messages from user has an image, but set disable_image to True for the others
for msg in self.session.messages[-2:]: for msg in self.session.messages[-2:]:
msg.disable_image = True msg.image = None
logger.debug( logger.debug(
self.session.messages self.session.messages
) )
@ -96,7 +96,7 @@ class AIProcessor:
aic.Message(role="assistant", content=output_text) aic.Message(role="assistant", content=output_text)
) )
return outputs return [*outputs]
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
return f"Error processing request: {str(e)}" return [f"Error processing request: {str(e)}"]

View File

@ -1,6 +1,8 @@
import logging import logging
import os import os
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
from dotenv import load_dotenv
load_dotenv()
# Configuration values # Configuration values
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper() LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()