@@ -39,7 +39,7 @@ def parse(
3939 - mode == 'fine': use LLM to parse structured topic/keys/tags
4040 """
4141 if mode == "fast" :
42- return self ._parse_fast (task_description , ** kwargs )
42+ return self ._parse_fast (task_description , context = context , ** kwargs )
4343 elif mode == "fine" :
4444 if not self .llm :
4545 raise ValueError ("LLM not provided for slow mode." )
@@ -51,6 +51,7 @@ def _parse_fast(self, task_description: str, **kwargs) -> ParsedTaskGoal:
5151 """
5252 Fast mode: simple jieba word split.
5353 """
54+ context = kwargs .get ("context" , "" )
5455 use_fast_graph = kwargs .get ("use_fast_graph" , False )
5556 if use_fast_graph :
5657 desc_tokenized = self .tokenizer .tokenize_mixed (task_description )
@@ -61,6 +62,7 @@ def _parse_fast(self, task_description: str, **kwargs) -> ParsedTaskGoal:
6162 goal_type = "default" ,
6263 rephrased_query = task_description ,
6364 internet_search = False ,
65+ context = context ,
6466 )
6567 else :
6668 return ParsedTaskGoal (
@@ -70,6 +72,7 @@ def _parse_fast(self, task_description: str, **kwargs) -> ParsedTaskGoal:
7072 goal_type = "default" ,
7173 rephrased_query = task_description ,
7274 internet_search = False ,
75+ context = context ,
7376 )
7477
7578 def _parse_fine (
@@ -91,16 +94,17 @@ def _parse_fine(
9194 logger .info (f"Parsing Goal... LLM input is { prompt } " )
9295 response = self .llm .generate (messages = [{"role" : "user" , "content" : prompt }])
9396 logger .info (f"Parsing Goal... LLM Response is { response } " )
94- return self ._parse_response (response )
97+ return self ._parse_response (response , context = context )
9598 except Exception :
9699 logger .warning (f"Fail to fine-parse query { query } : { traceback .format_exc ()} " )
97- return self ._parse_fast (query )
100+ return self ._parse_fast (query , context = context )
98101
99- def _parse_response (self , response : str ) -> ParsedTaskGoal :
102+ def _parse_response (self , response : str , ** kwargs ) -> ParsedTaskGoal :
100103 """
101104 Parse LLM JSON output safely.
102105 """
103106 try :
107+ context = kwargs .get ("context" , "" )
104108 response = response .replace ("```" , "" ).replace ("json" , "" ).strip ()
105109 response_json = eval (response )
106110 return ParsedTaskGoal (
@@ -110,6 +114,7 @@ def _parse_response(self, response: str) -> ParsedTaskGoal:
110114 rephrased_query = response_json .get ("rephrased_instruction" , None ),
111115 internet_search = response_json .get ("internet_search" , False ),
112116 goal_type = response_json .get ("goal_type" , "default" ),
117+ context = context ,
113118 )
114119 except Exception as e :
115120 raise ValueError (f"Failed to parse LLM output: { e } \n Raw response:\n { response } " ) from e
0 commit comments