From e26d59da970088426c03b54fda98e4d8aab5da31 Mon Sep 17 00:00:00 2001 From: "hemanth.hm" Date: Fri, 5 May 2023 20:19:58 -0700 Subject: [PATCH] Fix: indexError for `[]` `candidates` This PR fixes the `indexError` but not the root cause. --- google/generativeai/discuss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/generativeai/discuss.py b/google/generativeai/discuss.py index f463e2abd..6b976aef6 100644 --- a/google/generativeai/discuss.py +++ b/google/generativeai/discuss.py @@ -440,7 +440,7 @@ def _build_chat_response( request["messages"] = prompt["messages"] response = type(response).to_dict(response) - request["messages"].append(response["candidates"][0]) + request["messages"].extend(response.get("candidates", [])[:1]) request.setdefault("temperature", None) request.setdefault("candidate_count", None)