Skip to content

Fix reasoning and web search output for OpenAI compatibility#4

Open
Nick768 wants to merge 1 commit into
sums001:mainfrom
Nick768:fix/reasoning-and-search
Open

Fix reasoning and web search output for OpenAI compatibility#4
Nick768 wants to merge 1 commit into
sums001:mainfrom
Nick768:fix/reasoning-and-search

Conversation

@Nick768

@Nick768 Nick768 commented Jul 2, 2026

Copy link
Copy Markdown

Summary

  • Reasoning (DeepThink): THINK and RESPONSE fragments are now separated. THINK content is mapped to OpenAI's reasoning_content delta field; RESPONSE content stays in content. Previously all fragment types were mixed into content, producing garbled output.
  • Web search: SEARCH/TOOL_SEARCH/TOOL_OPEN fragment results are captured and returned as a citations array in the response, so clients can display source links. The parser now handles the current API format (fragment type SEARCH, implicit path frames without explicit "o" field) in addition to the documented format.

Changes

File Change
deepseek/client.py Rewrote _parse_sse to track fragment types, handle BATCH operations, bare BATCH arrays, and implicit path frames. Added _scan_for_sources for resilient citation extraction. _Stream now yields (type, text) tuples.
server/openai_format.py stream_chunks emits reasoning_content delta for thinking chunks. completion_response includes optional reasoning_content and citations.
server/api.py Passes reasoning_text and citations through to the response.
examples/03_direct_stream.py Updated for tuple-based iteration.
.gitignore Added shell.nix.

Test plan

  • Non-streaming with thinking: true returns reasoning_content in message
  • Non-streaming with search: true returns citations array
  • Streaming emits correct reasoning_content / content delta chunks
  • HAR dump from chat.deepseek.com parses correctly (validated offline)
  • Live SSE dump from current API parses correctly (12 citations captured)

🤖 Generated with Claude Code

- Separate THINK and RESPONSE fragments into reasoning_content
  and content respectively, matching OpenAI's delta format
- Capture SEARCH/TOOL_SEARCH/TOOL_OPEN results as a citations
  array in the response
- Handle BATCH operations, implicit path frames, and bare
  BATCH arrays in the SSE parser
- Add shell.nix to .gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant