mirror of
https://github.com/Jeuners/ECC.git
synced 2026-09-09 15:02:30 +02: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:
parent
43822b9c1a
commit
cc62e89152
2 changed files with 5 additions and 1 deletions
|
|
@ -79,6 +79,8 @@ class _AstraflowBaseProvider(LLMProvider):
|
|||
params["tools"] = [tool.to_openai_tool() for tool in llm_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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue