Handle DeepSeek reasoning_content fallback for empty responses
This commit is contained in:
@@ -170,12 +170,18 @@ class Assistant(commands.Cog):
|
|||||||
return f"Request failed: {exc}"
|
return f"Request failed: {exc}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reply = data["choices"][0]["message"]["content"]
|
choice = data["choices"][0]["message"]
|
||||||
|
reply = choice.get("content") or ""
|
||||||
|
# Some models (e.g. DeepSeek) put their response in reasoning_content
|
||||||
|
if not reply.strip():
|
||||||
|
reasoning = choice.get("reasoning_content") or ""
|
||||||
|
if reasoning.strip():
|
||||||
|
reply = reasoning
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
return f"Unexpected API response: {str(data)[:300]}"
|
return f"Unexpected API response: {str(data)[:300]}"
|
||||||
|
|
||||||
if not reply:
|
if not reply or not reply.strip():
|
||||||
return f"Empty response. Raw: {str(data)[:300]}"
|
return "The model returned an empty response. Try rephrasing or switching models."
|
||||||
|
|
||||||
self.history[key].append({"role": "assistant", "content": reply})
|
self.history[key].append({"role": "assistant", "content": reply})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user