mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-18 14:53:05 +08:00
fix: guard against empty choices in OpenAI and AstraFlow LLM providers
The OpenAI-compatible API can return HTTP 200 with an empty choices list or choices[0].message = None (content-filtered responses on Gemini, overwhelmed Ollama instances). Without a guard, both sites raise an unhandled IndexError or AttributeError crashing the provider. Added guard in OpenAIProvider.generate() and AstraFlowProvider.generate().
This commit is contained in:
@@ -79,6 +79,8 @@ class _AstraflowBaseProvider(LLMProvider):
|
|||||||
params["tools"] = [tool.to_openai_tool() for tool in llm_input.tools]
|
params["tools"] = [tool.to_openai_tool() for tool in llm_input.tools]
|
||||||
|
|
||||||
response = self.client.chat.completions.create(**params)
|
response = self.client.chat.completions.create(**params)
|
||||||
|
if not response.choices or response.choices[0].message is None:
|
||||||
|
raise ValueError("LLM returned empty or filtered response")
|
||||||
choice = response.choices[0]
|
choice = response.choices[0]
|
||||||
|
|
||||||
tool_calls = None
|
tool_calls = None
|
||||||
|
|||||||
@@ -67,9 +67,11 @@ class OpenAIProvider(LLMProvider):
|
|||||||
if input.max_tokens:
|
if input.max_tokens:
|
||||||
params["max_tokens"] = input.max_tokens
|
params["max_tokens"] = input.max_tokens
|
||||||
if input.tools:
|
if input.tools:
|
||||||
params["tools"] = [tool.to_openai_tool() for tool in input.tools]
|
params["tools"] = [tool.to_openai_tool() for tool in input.tools]
|
||||||
|
|
||||||
response = self.client.chat.completions.create(**params)
|
response = self.client.chat.completions.create(**params)
|
||||||
|
if not response.choices or response.choices[0].message is None:
|
||||||
|
raise ValueError("LLM returned empty or filtered response")
|
||||||
choice = response.choices[0]
|
choice = response.choices[0]
|
||||||
|
|
||||||
tool_calls = None
|
tool_calls = None
|
||||||
|
|||||||
Reference in New Issue
Block a user