From 1d8c880b5c4491899e571016f3e163e63b29074c Mon Sep 17 00:00:00 2001 From: mugesh Date: Fri, 3 Jan 2025 11:34:38 +0530 Subject: [PATCH] Fix TypeError in response handling by using f-string formatting for suggestion values --- opto/trace/utils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/opto/trace/utils.py b/opto/trace/utils.py index 0b59fab2..999e6a30 100644 --- a/opto/trace/utils.py +++ b/opto/trace/utils.py @@ -67,13 +67,11 @@ def render_opt_step(step_idx, optimizer, no_trace_graph=False, no_improvement=Fa llm_response = json.loads(optimizer.log[idx]['response']) r1 = llm_response['reasoning'] - if 'suggestion' in llm_response and llm_response['suggestion'] is not None: - a1 = "" - for var_name, var_body in llm_response['suggestion'].items(): - a1 += var_name + ':\n\n' - a1 += var_body + '\n\n' - - elif 'answer' in llm_response and llm_response['answer'] is not None: + if llm_response.get('suggestion'): + a1 = ''.join( + [f"{var_name}:\n\n{var_body}\n\n" for var_name, var_body in llm_response['suggestion'].items()] + ) + elif llm_response.get('answer') is not None: a1 = llm_response['answer'] else: a1 = " NULL/INVALID RESPONSE"