tb_tst_ai / utils /convo_utils.py
Daniil
Pushing the repo
17d7268
import pandas as pd
from datetime import datetime
import os
def submit_conversation(messages, user_name, start_time, model_number, prompt_architecture):
os.makedirs("conversations", exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
base_file_name = f"conversations/{timestamp}_convo"
# Save conversation as CSV
csv_file_name = f"{base_file_name}.csv"
data = [{"Role": msg["role"], "Content": msg["content"]} for msg in messages]
df = pd.DataFrame(data)
df.to_csv(csv_file_name, index=False)
# Calculate metadata
end_time = datetime.now()
total_time = end_time - start_time
num_turns = len(messages)
# Save metadata as TXT
txt_file_name = f"{base_file_name}.txt"
with open(txt_file_name, "w") as file:
file.write(f"User Name: {user_name}\n")
file.write(f"Conversation Date & Time: {end_time.strftime('%Y-%m-%d %H:%M:%S')}\n")
file.write(f"Total Turns: {num_turns}\n")
file.write(f"Total Conversation Time: {total_time}\n")
file.write(f"Model Number: {model_number}\n")
file.write(f"Prompt Architecture: {prompt_architecture}\n")
return csv_file_name, txt_file_name