From ef09ca32812e24626e0bd0e00e728b96dbadd147 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 19 Sep 2024 23:00:28 -0700 Subject: [PATCH] fixes for chat --- App_Function_Libraries/Chat.py | 10 ++++------ App_Function_Libraries/Gradio_UI/Chat_ui.py | 7 ++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/App_Function_Libraries/Chat.py b/App_Function_Libraries/Chat.py index 323cfebac..7120c0deb 100644 --- a/App_Function_Libraries/Chat.py +++ b/App_Function_Libraries/Chat.py @@ -97,12 +97,10 @@ def chat(message, history, media_content, selected_parts, api_endpoint, api_key, # logging.debug(f"Debug - Chat Function - Combined Content: {combined_content[:500]}...") # Prepare the input for the API - if not history: - input_data = f"{combined_content}\n\nUser: {message}\n" - else: - input_data = f"User: {message}\n" - # Print first 500 chars - # logging.info(f"Debug - Chat Function - Input Data: {input_data[:500]}...") + input_data = f"{combined_content}\n\n" if combined_content else "" + for old_message, old_response in history: + input_data += f"User: {old_message}\nAssistant: {old_response}\n\n" + input_data += f"User: {message}\n" if system_message: print(f"System message: {system_message}") diff --git a/App_Function_Libraries/Gradio_UI/Chat_ui.py b/App_Function_Libraries/Gradio_UI/Chat_ui.py index 4f5831c6c..dc3f8b03f 100644 --- a/App_Function_Libraries/Gradio_UI/Chat_ui.py +++ b/App_Function_Libraries/Gradio_UI/Chat_ui.py @@ -95,20 +95,21 @@ def chat_wrapper(message, history, media_content, selected_parts, api_endpoint, # Generate bot response bot_message = chat(full_message, history, media_content, selected_parts, api_endpoint, api_key, custom_prompt, temperature, system_prompt) + logging.debug(f"Bot message being returned: {bot_message}") + if save_conversation: # Add assistant message to the database add_chat_message(conversation_id, "assistant", bot_message) # Update history - history.append((message, bot_message)) + new_history = history + [(message, bot_message)] - return bot_message, history, conversation_id + return bot_message, new_history, conversation_id except Exception as e: logging.error(f"Error in chat wrapper: {str(e)}") return "An error occurred.", history, conversation_id - def search_conversations(query): try: conversations = search_chat_conversations(query)