From 71f9d1989f4000838234306ef86538c396b24e5f Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sat, 13 May 2023 23:04:31 -0300 Subject: [PATCH] Improved on topic generation and limiting topic sizes --- app.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index d1bcd08..7116383 100644 --- a/app.py +++ b/app.py @@ -90,8 +90,9 @@ def get_random_topic() -> str: completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=format_message( - "Give me a random list of 30 topics to talk about in a comma separated list. Each " - "topic should be less than 5 words long and should not contain commas" + "Give me a random list of 10 topics to talk about in a comma separated list. Each topic should be less " + "than 5 words long and should not contain commas. Be as creative as possible and choose topics from " + "multiple genres and industries." ), ) @@ -168,7 +169,11 @@ def topic(): topic = request.args.get("topic", None) if not topic: return redirect("/start") - if len(topic.split("_")) > 5: + + unslugified_topic = topic.replace("-", " ").replace("_", " ").replace("%20", " ").replace("\n", " ") + + if len(unslugified_topic.split()) > 5: + logging.info(f"The topic is too long: {unslugified_topic}") return "Error! Your topic should be < 5 words" - return get_chatgpt_html_response(topic) + return get_chatgpt_html_response(unslugified_topic)