Fix DeepSeek chat models failing with unavailable response_format (#1336) - #1337
Open
eldar702 wants to merge 1 commit into
Open
Fix DeepSeek chat models failing with unavailable response_format (#1336)#1337eldar702 wants to merge 1 commit into
eldar702 wants to merge 1 commit into
Conversation
…oj-ai#1336) get_structured_output_support only special-cased deepseek-reasoner, so deepseek-chat (and other non-reasoner DeepSeek models served over the official api.deepseek.com endpoint) fell through to StructuredOutputSupport.TOOL. The DeepSeek API only supports response_format={"type": "json_object"} and rejects tool/json_schema structured output with HTTP 400 "This response_format type is unavailable now", leaving an empty Khoj response. Gate the api.deepseek.com host to StructuredOutputSupport.OBJECT, mirroring the existing deepinfra/azure handling. Add DB-free regression tests covering deepseek-chat (OBJECT), deepseek-reasoner (NONE) and the default OpenAI path (TOOL). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
eldar702
marked this pull request as ready for review
June 10, 2026 06:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1336.
Problem
Any DeepSeek OpenAI-compatible chat model that is not
deepseek-reasoner(e.g.deepseek-chat, the flagship V3) fails every request over the officialapi.deepseek.comendpoint with HTTP 400invalid_request_error: This response_format type is unavailable now, so the chat turn is saved with an empty Khoj response.Fix
get_structured_output_supportinsrc/khoj/processor/conversation/openai/utils.pyonly special-caseddeepseek-reasoner(→NONE); every other DeepSeek model fell through toStructuredOutputSupport.TOOL. The official DeepSeek API only supportsresponse_format={"type": "json_object"}and rejects tool/json_schema structured output. The fix gates theapi.deepseek.comhost toStructuredOutputSupport.OBJECT, mirroring the existingapi.deepinfra.com/*.ai.azure.comhandling in the same function (1 file, 5 LOC, no new deps).Test
Added
tests/test_conversation_utils.py::TestGetStructuredOutputSupport(DB-free, pure-function).test_deepseek_chat_supports_object_outputassertsget_structured_output_support("deepseek-chat", "https://api.deepseek.com/v1") == StructuredOutputSupport.OBJECT— it fails before the fix (function returnsTOOL) and passes after. Two guard tests keepdeepseek-reasoner → NONEand the default OpenAI pathgpt-4o → TOOLgreen.Verification
pytest tests/test_conversation_utils.py -k TestGetStructuredOutputSupport— green (also full file: 14 passed)mypy src/khoj/processor/conversation/openai/utils.py— no new errors introduced (pre-existing baseline unchanged)ruff check/ruff format --check— clean🤖 AI-assistance disclosure: drafted with assistance from Claude (Opus 4.8). All changes reviewed for correctness before submission.