Add Chat Completions wrapper with reasoning conversion

Implements Phase 5: OpenAI Chat Completions compatibility layer

Features:
- Wraps Responses API for single source of truth
- Automatically enables reasoning generation
- Converts reasoning items to <think> tags for Open WebUI
- Maintains OpenAI-compatible chat completion format
- Supports both streaming and non-streaming modes
- Pipeline prefix preservation for model names
- System message handling

Architecture:
- Service layer calls Responses API internally
- Streams word-by-word for smooth UX
- Reasoning displayed in thought bubbles (Open WebUI)
- Main response shown separately from thinking

Error Handling:
- Enhanced exception types (RateLimitError, ContextLengthError)
- OpenAI-compatible error format
- Graceful error propagation from Responses API

Testing:
- 6 unit tests for chat router functionality
- 6 unit tests for streaming wrapper behavior
- Total: 12 tests with comprehensive coverage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-06 19:38:35 +01:00
co-authored by Claude
parent ff6c3cf1b5
commit 5e40704d91
4 changed files with 509 additions and 46 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ def test_chat_completion_non_streaming(
def test_chat_completion_validation_error(client: TestClient) -> None:
"""Test chat completion with invalid request."""
# Missing required field 'messages'
invalid_request = {"model": "mistral-nemo:latest"}
invalid_request = {"model": "tatlock"}
response = client.post("/v1/chat/completions", json=invalid_request)