Repository navigation
feat(nah_chat): add Responses API support - #27
Merged
Merged
Conversation
…onses() error path - Normalize CRLF on the whole SSE buffer so a \r\n pair split across network chunks is still joined (previously both events were silently dropped) - Add regression tests: CRLF boundary split, event: line fallback, [DONE] skip - responses() now returns ModelServerError with HTTP status on 4xx/5xx - Clear all clippy warnings in the new responses module
linmx0130
added a commit
that referenced
this pull request
Aug 2, 2026
…error surfacing (#28) Fixes for the chat completion API found by live-testing against DeepSeek V4 Flash. **Stacked on #27** (based on `feat/responses-api` to reuse its buffered SSE parser); the diff will shrink to just these fixes once #27 merges. ## Problems found & fixed ### P0 — stream event loss (up to 61% of deltas) `chat_completion_stream` split each raw `res.chunk()` on `\n\n` with no buffering — any SSE event crossing a network-chunk boundary was silently dropped. Replaying a **real captured DeepSeek stream** through the old parser at typical chunk sizes lost 22/36 deltas (511B) and 2/36 (4KB). This corrupts streaming text and tool-call argument deltas. Fixed by reusing `responses::SseBuffer` (buffered, CRLF-safe). After the fix: **0 loss at every chunk size from 3B to 4KB** on the same real stream. Regression test: `test_chat_stream_chunk_split_reassembly`. ### P1 — non-stream drops `reasoning_content` `ChatMessage.reasoning_content` was serde-renamed to `reasoningContent` (camelCase) while DeepSeek/Qwen send `reasoning_content` — chain-of-thought silently vanished from non-stream responses (stream mode already used the snake_case name and worked). Renamed to `reasoning_content`; verified live (non-stream now returns the reasoning text). Tests: `test_deserialize_reasoning_content_snake_case`, `test_serialize_reasoning_content_snake_case`. ### P1 — misleading error on 4xx/5xx (non-stream) `chat_completion` had no HTTP status check, so a 400 (e.g. unknown model) surfaced as "Invalid response format: missing choices field" instead of the server's message. Now mirrors the stream path and returns the server error body. Verified live: invalid model → real 400 body with the supported-model list. ## Live verification (deepseek-v4-flash) - non-stream + thinking: content + reasoning_content present - stream + thinking: text deltas + reasoning deltas, clean termination - tool call (nested schema) + tool result round-trip: complete arguments - error paths: proper 400/401 bodies
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.
Adds OpenAI Responses API support to
nah_chat(stream + non-stream), tested live against DeepSeekdeepseek-v4-flash(https://api.deepseek.com/responses).What's included
nah_chat/src/responses.rs(new):ResponsesInput/ResponseInputItem,ResponseObject(+output_text()/reasoning_text()/function_calls()),ResponseUsage,ResponsesStreamEvent(11 variants),ResponsesParamsBuilder, buffered SSE parser,impl ChatClient { create_responses_request, responses, responses_stream }examples/responses.rs(text + reasoning, stream & non-stream),examples/responses_tool.rs(function calling, flat tool schema)chat_completion_streaminfinite loop when the server closes the connection withoutdata: [DONE]Live verification (DeepSeek V4 Flash)
{"city": "San Francisco"}; Completed output item carries name=get_weather, arguments={...}Notes
deepseek-v4-flashfor now (v4-pro in early Aug 2026); unsupported params are silently ignored server-side{"type":"function","name":...,"parameters":...}), unlike chat completionsnahcrate integration (migratingnah/src/chat.rsto the Responses API) is a follow-up