From 5599313454927c91e502231125c7ea675490f5cd Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Mon, 12 May 2025 22:25:38 +0200 Subject: [PATCH] feat: Reduce debate rounds to 4 and enforce 100-word limit - Add word limit enforcement and shorter debates --- app.py | 2 +- participant.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 4148ca6..78260e6 100644 --- a/app.py +++ b/app.py @@ -9,7 +9,7 @@ def main(): random.shuffle(participants) opponents_answer = "Du bist der erste Teilnehmer in der ersten Runde. Was ist deine Meinung zum Thema?" - for i in range(10): + for i in range(4): print(f"Round {i + 1}") for participant in participants: diff --git a/participant.py b/participant.py index 8700c5f..684be22 100644 --- a/participant.py +++ b/participant.py @@ -36,6 +36,28 @@ class Participant: {"role": "system", "content": self.role_description}, ] + def truncate_to_word_limit(self, text, word_limit=100): + """Truncate text to specified word limit, ensuring to complete the last sentence.""" + words = text.split() + if len(words) <= word_limit: + return text + + # Get the first 100 words + truncated = words[:word_limit] + truncated_text = " ".join(truncated) + + # Find the last sentence end (., !, or ?) + last_sentence_end = max( + truncated_text.rfind("."), + truncated_text.rfind("!"), + truncated_text.rfind("?") + ) + + # If we found a sentence end, cut there, otherwise use the full 100 words + if last_sentence_end != -1: + return truncated_text[:last_sentence_end + 1] + return truncated_text + def answer(self, question): self.messages.append({"role": "user", "content": question}) @@ -44,6 +66,9 @@ class Participant: ) answer = response.choices[0].message.content + # Enforce 100-word limit while maintaining complete sentences + answer = self.truncate_to_word_limit(answer) + self.messages.append({"role": "assistant", "content": answer}) self.write_to_file(self.__class__.__name__, self.messages)