Skip to content

Commit

Permalink
fixes for chat
Browse files Browse the repository at this point in the history
  • Loading branch information
rmusser01 committed Sep 20, 2024
1 parent d05abea commit ef09ca3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 4 additions & 6 deletions App_Function_Libraries/Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
7 changes: 4 additions & 3 deletions App_Function_Libraries/Gradio_UI/Chat_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ef09ca3

Please sign in to comment.