Add check when the response is empty

{
  "id": "",
  "object": "",
  "created": 0,
  "model": "",
  "prompt_annotations": [
    {
      "prompt_index": 0,
      "content_filter_results": {
        "hate": { "filtered": false, "severity": "safe" },
        "self_harm": { "filtered": false, "severity": "safe" },
        "sexual": { "filtered": false, "severity": "safe" },
        "violence": { "filtered": false, "severity": "safe" }
      }
    }
  ],
  "choices": [],
  "usage": null
}


In newer versions of models, at times choices array can be empty
This commit is contained in:
Jay
2023-09-12 00:01:13 +05:30
committed by GitHub
parent d9959f9c49
commit 74cbe33421

View File

@@ -239,6 +239,10 @@ def stream_gpt_completion(data, req_type):
try:
json_line = json.loads(line)
if len(json_line['choices']) == 0:
continue
if 'error' in json_line:
logger.error(f'Error in LLM response: {json_line}')
raise ValueError(f'Error in LLM response: {json_line["error"]["message"]}')