From 25efdb07200a84baa2ae285d0d510c164da7128b Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Tue, 14 Nov 2023 07:25:10 -0500 Subject: [PATCH] modified: app.py --- app.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index b923762..f73e172 100644 --- a/app.py +++ b/app.py @@ -416,23 +416,40 @@ def gpt_generate_room_title(messages, model_name): """ Generate a title for the room based on a list of messages. """ - conversation = " ".join([msg.content for msg in messages]) + + chat_history = [ + { + "role": "system" + if ( + msg.username == "gpt-3.5-turbo" + or msg.username == "anthropic.claude-v1" + or msg.username == "anthropic.claude-v2" + or msg.username == "gpt-4" + or msg.username == "gpt-4-1106-preview" + ) + else "user", + "content": f"{msg.username}: {msg.content}", + } + for msg in reversed(messages) + ] + + chat_history.append( + { + "role": "system", + "content": "return a short title for the title bar of this conversation.", + } + ) # Interaction with LLM to generate summary # For example, using OpenAI's GPT model response = openai.ChatCompletion.create( - messages=[ - { - "role": "system", - "content": f"return a short title for the title bar for this conversation: {conversation}", - } - ], + messages=chat_history, model=model_name, # or any appropriate model max_tokens=20, # Adjust as needed ) title = response.choices[0]["message"]["content"] - return title.replace('"', '') + return title.replace('"', "") if __name__ == "__main__":