Skip to content

Commit 067c2d4

Browse files
committed
fix never give up issue
1 parent b6b4e19 commit 067c2d4

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

editscore/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def evaluate(self, image_prompts, text_prompt):
9292
while SC_dict is False or PQ_dict is False:
9393
tries += 1
9494
guess_if_cannot_parse = True if tries > max_tries else False
95+
9596
result_SC = self.model.inference(SC_prompt_final, seed=self.seed + i)
9697
result_PQ = self.model.inference(PQ_prompt_final, seed=self.seed + i)
9798

editscore/utils.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)