mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-19 07:13:07 +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:
@@ -67,9 +67,11 @@ class OpenAIProvider(LLMProvider):
|
||||
if input.max_tokens:
|
||||
params["max_tokens"] = input.max_tokens
|
||||
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)
|
||||
if not response.choices or response.choices[0].message is None:
|
||||
raise ValueError("LLM returned empty or filtered response")
|
||||
choice = response.choices[0]
|
||||
|
||||
tool_calls = None
|
||||
|
||||
Reference in New Issue
Block a user