Skip to content

Commit 71cdd28

Browse files
committed
gracefully handle stream chunks without "choices" field
1 parent c8d41ac commit 71cdd28

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pilot/utils/llm_connection.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ def return_result(result_data, lines_printed):
486486
try:
487487
json_line = json.loads(line)
488488

489-
if len(json_line['choices']) == 0:
490-
continue
491-
492489
if 'error' in json_line:
493490
logger.error(f'Error in LLM response: {json_line}')
494491
telemetry.record_llm_request(token_count, time.time() - request_start_time, is_error=True)
495492
raise ValueError(f'Error in LLM response: {json_line["error"]["message"]}')
496493

494+
if 'choices' not in json_line or len(json_line['choices']) == 0:
495+
continue
496+
497497
choice = json_line['choices'][0]
498498

499499
# if 'finish_reason' in choice and choice['finish_reason'] == 'function_call':

0 commit comments

Comments
 (0)