@@ -211,6 +211,11 @@ def mllm_output_to_dict(input_string, give_up_parsing=False, text_prompt=None):
211211 if input_string == "rate_limit_exceeded" :
212212 return "rate_limit_exceeded"
213213
214+ if give_up_parsing :
215+ guessed_value = random .randint (0 , 10 )
216+ json_content = {'score' : [guessed_value ], "reasoning" : f"guess_if_cannot_parse | { input_string } " }
217+ return json_content
218+
214219 # Define the delimiters
215220 delimiter = '||V^=^V||'
216221
@@ -233,15 +238,7 @@ def mllm_output_to_dict(input_string, give_up_parsing=False, text_prompt=None):
233238 # this time we will just get the scores and ignore the reasoning (other part of the json)
234239 start_index = input_string .find ('[' )
235240 end_index = input_string .rfind (']' ) + 1
236- if give_up_parsing : # if we want to give up parsing
237- guessed_value = random .randint (0 , 10 )
238- print (f"1111 Failed to find the json content in the string. Guess a value : { text_prompt = } { input_string = } { guessed_value = } ." , flush = True )
239- json_content = {'score' : [guessed_value ], "reasoning" : f"guess_if_cannot_parse | { input_string } " }
240- json_str = json .dumps (json_content )
241- input_string = json_str
242- start_index = 0
243- end_index = len (json_str )
244- elif re .match (r'^\[\d+, ?\d+\]$' , input_string [start_index :end_index ]):
241+ if re .match (r'^\[\d+, ?\d+\]$' , input_string [start_index :end_index ]):
245242 scores = json .loads (input_string [start_index :end_index ])
246243 if not isinstance (scores , list ):
247244 scores = [scores ]
0 commit comments