Skip to content

Commit 0db6021

Browse files
committed
fix output parsing
1 parent 2529d08 commit 0db6021

File tree

1 file changed

+48
-31
lines changed

1 file changed

+48
-31
lines changed

reverie/backend_server/persona/prompt_template/run_gpt_prompt.py

+48-31
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,20 @@ def create_prompt_input(persona, task, duration, test_input=None):
356356
prompt_input += [persona.scratch.get_str_firstname()]
357357
return prompt_input
358358

359-
def __func_clean_up(gpt_response, prompt=""):
360-
print (gpt_response)
361-
print ("-==- -==- -==- ")
359+
def extract_numeric_part(k):
360+
# Use regular expression to find all digits
361+
numeric_part = re.findall(r'\d+', k)
362+
# Join all found digits into a single string and convert to int
363+
return int(numeric_part[0])
362364

365+
def __func_clean_up(gpt_response, prompt=""):
366+
367+
debug = True
368+
369+
if debug:
370+
print (gpt_response)
371+
print ("-==- -==- -==- ")
372+
print("(cleanup func): Enter function")
363373
# TODO SOMETHING HERE sometimes fails... See screenshot
364374
temp = [i.strip() for i in gpt_response.split("\n")]
365375
_cr = []
@@ -370,22 +380,49 @@ def __func_clean_up(gpt_response, prompt=""):
370380
else:
371381
_cr += [i]
372382
for count, i in enumerate(_cr):
383+
if debug:
384+
print("(cleanup func) Unpacking: ", i)
385+
386+
# Original version
387+
# k = [j.strip() for j in i.split("(duration in minutes:")]
388+
373389
# Sometimes the simulation fails because it doesn't contain
374390
# `duration in minutes` but only `duration`.
375391
if "duration in minutes" in i:
376392
k = [j.strip() for j in i.split("(duration in minutes:")]
377393
else:
378394
k = [j.strip() for j in i.split("(duration:")]
379-
# k = [j.strip() for j in i.split("(duration in minutes:")]
395+
396+
if debug:
397+
print("(cleanup func) Unpacked(k): ", k)
380398
task = k[0]
381399
if task[-1] == ".":
382400
task = task[:-1]
383-
duration = int(k[1].split(",")[0].strip())
401+
minutes = k[1].split(",")[0]
402+
403+
if debug:
404+
print("(cleanup func): Minutes: ", minutes)
405+
duration = extract_numeric_part(minutes)
406+
if debug:
407+
print("(cleanup func): Duration: ", duration)
408+
409+
# Original version
410+
# duration = int(k[1].split(",")[0].strip())
411+
384412
cr += [[task, duration]]
413+
414+
if debug:
415+
print("(cleanup func) Unpacked(cr): ", cr)
385416

417+
if debug:
418+
print("(cleanup func) Prompt:", prompt)
419+
386420
total_expected_min = int(prompt.split("(total duration in minutes")[-1]
387421
.split("):")[0].strip())
388422

423+
if debug:
424+
print("(cleanup func) Expected Minutes:", total_expected_min)
425+
389426
# TODO -- now, you need to make sure that this is the same as the sum of
390427
# the current action sequence.
391428
curr_min_slot = [["dummy", -1],] # (task_name, task_index)
@@ -439,8 +476,6 @@ def get_fail_safe():
439476
prompt = generate_prompt(prompt_input, prompt_template)
440477
fail_safe = get_fail_safe()
441478

442-
print ("?????")
443-
print (prompt)
444479
output = safe_generate_response(prompt, gpt_param, 5, get_fail_safe(),
445480
__func_validate, __func_clean_up)
446481

@@ -454,11 +489,12 @@ def get_fail_safe():
454489
IndexError: list index out of range
455490
"""
456491

457-
print ("IMPORTANT VVV DEBUG")
458-
459-
# print (prompt_input)
492+
# Some debugging prints
493+
# print ("DEBUG")
494+
# print("PROMPT:")
460495
# print (prompt)
461-
print (output)
496+
# print("\nOUTPUT:")
497+
# print (output)
462498

463499
fin_output = []
464500
time_sum = 0
@@ -2913,23 +2949,4 @@ def get_fail_safe():
29132949
gpt_param = {"engine": "gpt-35-turbo-0125", "max_tokens": 50,
29142950
"temperature": 0, "top_p": 1, "stream": False,
29152951
"frequency_penalty": 0, "presence_penalty": 0, "stop": None}
2916-
return output, [output, prompt, gpt_param, prompt_input, fail_safe]
2917-
2918-
2919-
2920-
2921-
2922-
2923-
2924-
2925-
2926-
2927-
2928-
2929-
2930-
2931-
2932-
2933-
2934-
2935-
2952+
return output, [output, prompt, gpt_param, prompt_input, fail_safe]

0 commit comments

Comments
 (0)