From effcad78db4cd3aa458eb5ced242b5940cfa36da Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Sat, 29 Mar 2025 21:38:08 +0100 Subject: [PATCH] Log as markdown --- app.py | 2 +- participant.py | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 5f00905..9b76f80 100644 --- a/app.py +++ b/app.py @@ -14,7 +14,7 @@ def main(): exit opponents_answer = "Du bist der erste Teilnehmer in der ersten Runde. Was ist deine Meinung zum Thema?" - for i in range(4): + for i in range(20): print(f"Round {i+1}") for participant in participants: diff --git a/participant.py b/participant.py index 54c9a0d..2c8d7ee 100644 --- a/participant.py +++ b/participant.py @@ -24,7 +24,11 @@ class Participant: self.name = f"""{name} {fake.name()}""" self.client = Mistral(api_key=api_key) self.role_description = role_description - os.remove(f"log/{self.__class__.__name__}.txt") + + try: + os.remove(f"log/{self.__class__.__name__}.md") + except FileNotFoundError: + pass self.messages = [{"role": "system", "content": basic_instruction}, {"role": "system", "content": self.role_description}] @@ -33,6 +37,7 @@ class Participant: self.messages.append({"role": "user", "content": question}) response = self.client.chat.complete( + temperature=0.7, model="mistral-large-latest", messages=self.messages) @@ -44,10 +49,20 @@ class Participant: return answer def write_to_file(self, filename, messages): - with open(f"log/{filename}.txt", "w") as file: + with open(f"log/{filename}.md", "w") as file: for message in messages: - file.write(f"{message['role']}: {message['content']}\n\n") - file.write("----------------------------------------------------------\n\n") + role = "unknown" + match message['role']: + case "system": + role = "System Prompt" + case "user": + role = "Gegnerische Antwort" + case "assistant": + role = "Meine Antwort" + + file.write(f"## {role}\n") + + file.write(f"{message['content']}\n\n") class ProParticipant(Participant):