test async
This commit is contained in:
32
parse_questions.py
Normal file
32
parse_questions.py
Normal 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)
|
||||
Reference in New Issue
Block a user