55from graphgen .bases import BaseGraphStorage , BaseKVStorage , BaseLLMWrapper
66from graphgen .common import init_llm , init_storage
77from graphgen .models import QuizGenerator
8- from graphgen .utils import compute_content_hash , logger , run_concurrent
8+ from graphgen .utils import compute_dict_hash , logger , run_concurrent
99
1010
1111class QuizService :
@@ -20,7 +20,7 @@ def __init__(
2020 self .graph_storage : BaseGraphStorage = init_storage (
2121 backend = "networkx" , working_dir = working_dir , namespace = "graph"
2222 )
23- # { _description_id : { "description": str, "quizzes": List[Tuple[str, str]] } }
23+ # { _quiz_id : { "description": str, "quizzes": List[Tuple[str, str]] } }
2424 self .quiz_storage : BaseKVStorage = init_storage (
2525 backend = "json_kv" , working_dir = working_dir , namespace = "quiz"
2626 )
@@ -37,8 +37,8 @@ def __call__(self, batch: pd.DataFrame) -> Iterable[pd.DataFrame]:
3737 async def _process_single_quiz (self , item : tuple ) -> dict | None :
3838 # if quiz in quiz_storage exists already, directly get it
3939 index , desc = item
40- _description_id = compute_content_hash ( desc , prefix = "quiz-" )
41- if self .quiz_storage .get_by_id (_description_id ):
40+ _quiz_id = compute_dict_hash ({ "index" : index , "description" : desc } )
41+ if self .quiz_storage .get_by_id (_quiz_id ):
4242 return None
4343
4444 tasks = []
@@ -56,7 +56,7 @@ async def _process_single_quiz(self, item: tuple) -> dict | None:
5656 rephrased_text = self .generator .parse_rephrased_text (new_description )
5757 quizzes .append ((rephrased_text , gt ))
5858 return {
59- "_description_id " : _description_id ,
59+ "_quiz_id " : _quiz_id ,
6060 "description" : desc ,
6161 "index" : index ,
6262 "quizzes" : quizzes ,
@@ -100,7 +100,7 @@ def quiz(self) -> Iterable[pd.DataFrame]:
100100 if new_result :
101101 self .quiz_storage .upsert (
102102 {
103- new_result ["_description_id " ]: {
103+ new_result ["_quiz_id " ]: {
104104 "description" : new_result ["description" ],
105105 "quizzes" : new_result ["quizzes" ],
106106 }
0 commit comments