File size: 1,331 Bytes
b52f9d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import importlib.util
from pathlib import Path

from config import CONFIG
from inference import RAGEngine


def _load_data_loader_module():
	module_path = Path(__file__).with_name("data-loader.py")
	spec = importlib.util.spec_from_file_location("data_loader", module_path)
	if spec is None or spec.loader is None:
		raise RuntimeError("Could not load data-loader.py")

	module = importlib.util.module_from_spec(spec)
	spec.loader.exec_module(module)
	return module

def main() -> None:
	data_loader = _load_data_loader_module()
	try:
		questions = data_loader.load_questions()
	except Exception:
		questions = []

	if not questions:
		questions_path = CONFIG.data_path.with_name("questions.txt")
		if questions_path.exists():
			questions = [line.strip() for line in questions_path.read_text(encoding="utf-8").splitlines() if line.strip()]

	if not questions:
		print("No questions found in the downloaded dataset or fallback file.")
		return

	engine = RAGEngine()
	CONFIG.output_path.parent.mkdir(parents=True, exist_ok=True)

	with CONFIG.output_path.open("w", encoding="utf-8") as f:
		for question in questions:
			result = engine.answer(question)
			f.write(json.dumps(result, ensure_ascii=False) + "\n")

	print(f"Saved {len(questions)} predictions to {CONFIG.output_path}")


if __name__ == "__main__":
	main()