From 19e6b7579e3764e12a3a9decb73aa11586a1fea3 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sun, 29 Oct 2023 15:09:51 -0400 Subject: [PATCH] modified: app.py --- app.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index c080c21..daf465b 100644 --- a/app.py +++ b/app.py @@ -84,16 +84,17 @@ def handle_message(data): emit("message", f"{data['username']}: {data['message']}", room=data["room"]) if "claude" in data["message"] or "gpt" in data["message"]: + + if "claude" in data["message"]: + func = chat_claude + elif "gpt" in data["message"]: + func = chat_gpt + # Emit a temporary message indicating that llm is processing emit("message", f"Processing...", room=data["room"]) - if "claude" in data["message"]: # Call the chat_claude function without blocking using eventlet.spawn - eventlet.spawn(chat_claude, data["username"], data["room"], data["message"]) - - elif "gpt" in data["message"]: - # Call the chat_gpt function without blocking using eventlet.spawn - eventlet.spawn(chat_gpt, data["username"], data["room"], data["message"]) + eventlet.spawn(func, data["username"], data["room"], data["message"]) def chat_claude(username, room, message): @@ -109,10 +110,10 @@ def chat_claude(username, room, message): chat_history = "" for msg in reversed(all_messages): - if msg.username not in ["gpt-3.5-turbo", "anthropic.claude-v2"]: - chat_history += f"Human: {msg.username}: {msg.content}\n\n" + if msg.username in ["gpt-3.5-turbo", "anthropic.claude-v2"]: + chat_history += f"Assistant: {msg.username}: {msg.content}\n\n" else: - chat_history += f"Assistant: {msg.content}\n\n" + chat_history += f"Human: {msg.username}: {msg.content}\n\n" # append the new message. chat_history += f"Human: {username}: {message}\n\nAssistant:"