mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
fix(openai): improve error message for null choices in OpenAI-compatible APIs (#35236)
This commit is contained in:
@@ -1520,7 +1520,15 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
raise KeyError(msg) from e
|
||||
|
||||
if choices is None:
|
||||
msg = "Received response with null value for `choices`."
|
||||
# Some OpenAI-compatible APIs (e.g., vLLM) may return null choices
|
||||
# when the response format differs or an error occurs without
|
||||
# populating the error field. Provide a more helpful error message.
|
||||
msg = (
|
||||
"Received response with null value for `choices`. "
|
||||
"This can happen when using OpenAI-compatible APIs (e.g., vLLM) "
|
||||
"that return a response in an unexpected format. "
|
||||
f"Full response keys: {list(response_dict.keys())}"
|
||||
)
|
||||
raise TypeError(msg)
|
||||
|
||||
token_usage = response_dict.get("usage")
|
||||
|
||||
Reference in New Issue
Block a user