feat: Reduce debate rounds to 4 and enforce 100-word limit - Add word limit enforcement and shorter debates

This commit is contained in:
2025-05-12 22:25:38 +02:00
parent d4dd4fe826
commit 5599313454
2 changed files with 26 additions and 1 deletions
+1 -1
View File
@@ -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:
+25
View File
@@ -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)