diff --git a/ai/ai_utils/handle_response.py b/ai/ai_utils/handle_response.py index 87955fd..238d6ce 100644 --- a/ai/ai_utils/handle_response.py +++ b/ai/ai_utils/handle_response.py @@ -20,9 +20,10 @@ def _get_provider(api_name: str): return AnthropicAPI() -def get_ai_response(user_id: str, prompt: str, context="", system_content=DEFAULT_SYSTEM_CONTENT): +def get_ai_response(user_id: str, prompt: str, context: list = [], system_content=DEFAULT_SYSTEM_CONTENT): try: - full_prompt = f"{prompt} {context}" + formatted_context = "\n".join([f"{msg['user']}: {msg['text']}" for msg in context]) + full_prompt = f"Prompt: {prompt}\nContext: {formatted_context}" api_name, model_name = get_user_state(user_id) provider = _get_provider(api_name) provider.set_model(model_name) diff --git a/listeners/listener_utils/parse_conversation.py b/listeners/listener_utils/parse_conversation.py index 5032f55..2b48562 100644 --- a/listeners/listener_utils/parse_conversation.py +++ b/listeners/listener_utils/parse_conversation.py @@ -5,15 +5,14 @@ # and formats it as a string with user IDs and their messages. # Used in `app_mentioned_callback`, `dm_sent_callback`, # and `handle_summary_function_callback`. -def parse_conversation(conversation: str, bot_id: str = ""): - parsed = "" +def parse_conversation(conversation: str): + parsed = [] try: for message in conversation: user = message.get("user") text = message.get("text", "") - if user != bot_id: - parsed += f"{user}: {text}, " - return str(parsed) + parsed.append({"user": user, "text": text}) + return parsed except Exception as e: Logger.error(e) return None