feat: Reduce debate rounds to 4 and enforce 100-word limit - Add word limit enforcement and shorter debates
This commit is contained in:
@@ -9,7 +9,7 @@ def main():
|
|||||||
random.shuffle(participants)
|
random.shuffle(participants)
|
||||||
opponents_answer = "Du bist der erste Teilnehmer in der ersten Runde. Was ist deine Meinung zum Thema?"
|
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}")
|
print(f"Round {i + 1}")
|
||||||
|
|
||||||
for participant in participants:
|
for participant in participants:
|
||||||
|
|||||||
@@ -36,6 +36,28 @@ class Participant:
|
|||||||
{"role": "system", "content": self.role_description},
|
{"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):
|
def answer(self, question):
|
||||||
self.messages.append({"role": "user", "content": question})
|
self.messages.append({"role": "user", "content": question})
|
||||||
|
|
||||||
@@ -44,6 +66,9 @@ class Participant:
|
|||||||
)
|
)
|
||||||
|
|
||||||
answer = response.choices[0].message.content
|
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.messages.append({"role": "assistant", "content": answer})
|
||||||
|
|
||||||
self.write_to_file(self.__class__.__name__, self.messages)
|
self.write_to_file(self.__class__.__name__, self.messages)
|
||||||
|
|||||||
Reference in New Issue
Block a user