test async

This commit is contained in:
Matteo Rosati
2026-02-17 16:04:18 +01:00
parent 7b7bff6c8c
commit 719919920f
4 changed files with 74 additions and 281 deletions

32
parse_questions.py Normal file
View File

@@ -0,0 +1,32 @@
import os
def parse_questions(rag_chain):
domande_dir = "domande"
risposte_dir = "risposte"
os.makedirs(risposte_dir, exist_ok=True)
for filename in sorted(os.listdir(domande_dir)):
if not filename.lower().endswith(".txt"):
continue
domanda_path = os.path.join(domande_dir, filename)
with open(domanda_path, "r", encoding="utf-8") as f:
contents = f.read()
print(f"========== DOMANDA ({domanda_path}) ==========")
print(contents)
response = rag_chain.invoke(contents)
print("========== RISPOSTA ==========")
print(response)
print("\n\n")
base_name = os.path.splitext(filename)[0]
suffix = "".join(ch for ch in base_name if ch.isdigit()) or base_name
risposta_path = os.path.join(risposte_dir, f"risposta{suffix}.txt")
with open(risposta_path, "w", encoding="utf-8") as f:
f.write(response)