fix peer chat streaming#136
Conversation
|
""" WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API (chat endpoint)
participant Agent
participant StreamManager
Client->>API (chat endpoint): POST chat request (with options.stream)
alt options.stream == False
API->>Agent: agent.chat(...)
Agent-->>API: response
API-->>Client: response
else options.stream == True
API->>Agent: agent.chat(..., stream=True)
Agent-->>API: AsyncMessageStreamManager
loop for each chunk
API->>StreamManager: text_stream
StreamManager-->>API: text chunk
API-->>Client: text chunk (streamed)
end
alt error occurs
API->>API: log error
API-->>Client: HTTP 500 error
end
end
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/routers/peers.py (1)
154-154: Consider updating the response model for streaming compatibility.The endpoint declares
response_model=schemas.DialecticResponsebut returnsStreamingResponsewhen streaming is enabled. This mismatch may cause issues with OpenAPI documentation and client code generation.Consider using a Union type or removing the response_model declaration:
- response_model=schemas.DialecticResponse, + response_model=None, # or use Union[schemas.DialecticResponse, StreamingResponse]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/routers/peers.py(3 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
src/routers/peers.py
[refactor] 178-204: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it
(R1705)
🔇 Additional comments (2)
src/routers/peers.py (2)
4-4: LGTM! Required imports for streaming support.The added imports are necessary for the streaming functionality implementation.
Also applies to: 13-14
198-200: Review error handling in streaming context.The current error handling raises
HTTPExceptionduring streaming, which may cause issues if response headers have already been sent. Consider whether this is the intended behavior or if alternative error handling (like yielding error messages) would be more appropriate.Could you verify that raising
HTTPExceptionduring streaming works as expected in your FastAPI setup? In some cases, once streaming has started, HTTP status codes cannot be changed.
…chat-streaming fix peer chat streaming
Summary by CodeRabbit
New Features
Bug Fixes