|
22 | 22 | logger = logging.getLogger(__name__) |
23 | 23 |
|
24 | 24 |
|
25 | | -def patch_save_json(data, filename): |
26 | | - import json |
27 | | - import os |
28 | | - |
29 | | - path = f"/Users/shahules/Myprojects/ragas/experiments/{filename}.json" |
30 | | - if os.path.exists(path): |
31 | | - database = json.load(open(path)) |
32 | | - database = database if isinstance(database, list) else [database] |
33 | | - database.append(data) |
34 | | - else: |
35 | | - database = [data] |
36 | | - with open(path, "w") as f: |
37 | | - json.dump(database, f, indent=4) |
38 | | - |
39 | | - |
40 | 25 | @dataclass |
41 | 26 | class Filter(ABC): |
42 | 27 | llm: BaseRagasLLM |
@@ -71,8 +56,6 @@ async def filter(self, node: Node) -> t.Dict: |
71 | 56 | score = await json_loader.safe_load(output, llm=self.llm) |
72 | 57 | score = score if isinstance(score, dict) else {} |
73 | 58 | logger.debug("node filter: %s", score) |
74 | | - score.update({"context": node.page_content}) |
75 | | - patch_save_json(score, "node_filter") |
76 | 59 | score.update({"score": score.get("score", 0) >= self.threshold}) |
77 | 60 | return score |
78 | 61 |
|
@@ -104,8 +87,6 @@ async def filter(self, question: str) -> t.Tuple[bool, str]: |
104 | 87 | results = results.generations[0][0].text.strip() |
105 | 88 | json_results = await json_loader.safe_load(results, llm=self.llm) |
106 | 89 | json_results = json_results if isinstance(json_results, dict) else {} |
107 | | - json_results.update({"question": question}) |
108 | | - patch_save_json(json_results, "question_filter") |
109 | 90 | logger.debug("filtered question: %s", json_results) |
110 | 91 | return json_results.get("verdict") == "1", json_results.get("feedback", "") |
111 | 92 |
|
@@ -139,8 +120,6 @@ async def filter(self, simple_question: str, compressed_question: str) -> bool: |
139 | 120 | results = results.generations[0][0].text.strip() |
140 | 121 | json_results = await json_loader.safe_load(results, llm=self.llm) |
141 | 122 | json_results = json_results if isinstance(json_results, dict) else {} |
142 | | - json_results.update({"questions": [simple_question, compressed_question]}) |
143 | | - patch_save_json(json_results, "evolution_filter") |
144 | 123 | logger.debug("evolution filter: %s", json_results) |
145 | 124 | return json_results.get("verdict") == "1" |
146 | 125 |
|
|
0 commit comments