-
Notifications
You must be signed in to change notification settings - Fork 277
Adding OpenAI Chat Completions API compatibility #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rapids-bot
merged 7 commits into
NVIDIA:develop
from
dfagnou:df/openai-api-compatible-endpoint
Jul 24, 2025
Merged
Adding OpenAI Chat Completions API compatibility #421
rapids-bot
merged 7 commits into
NVIDIA:develop
from
dfagnou:df/openai-api-compatible-endpoint
Jul 24, 2025
+857
β31
Conversation
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
/ok to test d025ffa |
Signed-off-by: Damien Fagnou <[email protected]>
Signed-off-by: Damien Fagnou <[email protected]>
d025ffa
to
42e8ec4
Compare
ericevans-nv
previously requested changes
Jul 18, 2025
Signed-off-by: Yuchen Zhang <[email protected]>
/ok to test 958890c |
Signed-off-by: Yuchen Zhang <[email protected]>
/ok to test d1b6bc9 |
Signed-off-by: Yuchen Zhang <[email protected]>
/ok to test 91670ff |
Signed-off-by: Yuchen Zhang <[email protected]>
/ok to test 668ffa4 |
Signed-off-by: Yuchen Zhang <[email protected]>
/ok to test 0cf3a4f |
mdemoret-nv
approved these changes
Jul 24, 2025
/merge |
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.
OpenAI Chat Completions API Compatibility - Implementation
Date: Start January 7, 2025
Version: NeMo Agent Toolkit v0.1.dev213+
Status: β Ready to review
π― Executive Summary
implemented full OpenAI Chat Completions API compatibility for the NeMo Agent Toolkit FastAPI frontend. This enhancement enables seamless integration with existing OpenAI-compatible client libraries while maintaining 100% backward compatibility with existing deployments.
Key Achievements
π New Features
1. OpenAI Compatible Mode
Single endpoint that handles both streaming and non-streaming requests based on the
stream
parameter, exactly like the OpenAI API.Configuration:
Endpoints Created:
POST /v1/chat/completions
β Handles both streaming (stream: true
) and non-streaming (stream: false
)2. Enhanced Request Model (AIQChatRequest)
Now supports all OpenAI Chat Completions API parameters with proper validation:
frequency_penalty
logit_bias
logprobs
top_logprobs
max_tokens
n
presence_penalty
response_format
seed
service_tier
stop
stream
stream_options
temperature
top_p
tools
tool_choice
parallel_tool_calls
user
3. Enhanced Response Models
AIQChatResponse (Non-streaming)
AIQChatResponseChunk (Streaming)
4. Backward Compatible Legacy Mode
Preserves exact existing behavior when
openai_api_compatible: false
(default).Endpoints Created:
POST /v1/chat/completions
β Non-streaming (legacy behavior)POST /v1/chat/completions/stream
β Streaming (legacy behavior)π§ Technical Implementation
Files Modified
fastapi_front_end_config.py
openai_api_compatible
fieldapi_server.py
fastapi_front_end_plugin_worker.py
Core Components Added
@field_serializer
for OpenAI compatibilitystream
parameterKey Technical Decisions
message
anddelta
fields both optional inAIQChoice
π§ͺ Testing & Quality Assurance
Test Coverage Summary
New Test Categories
1. Configuration Tests
test_fastapi_config_openai_api_compatible_field
- New config field validationtest_openai_request_validation
- OpenAI parameter validation2. Data Model Tests
test_aiq_chat_request_openai_fields
- All OpenAI parameterstest_aiq_choice_delta_class
- New delta formattest_aiq_chat_response_chunk_create_streaming_chunk
- Streaming chunkstest_aiq_chat_response_timestamp_serialization
- Unix timestamps3. Endpoint Behavior Tests
test_legacy_vs_openai_compatible_mode_endpoints[True/False]
- Both modestest_openai_compatible_mode_stream_parameter
- Single endpoint routingtest_legacy_mode_backward_compatibility
- No breaking changes4. Compatibility Tests
test_converter_functions_backward_compatibility
- Legacy format supportQuality Metrics
π Usage Examples
OpenAI Python Client
AI SDK (JavaScript/TypeScript)
cURL Examples
π Migration Guide
For New Deployments (Recommended)
Use OpenAI Compatible Mode for new projects:
For Existing Deployments
No changes required. Existing configurations continue to work:
Gradual Migration
stream
parameteropenai_api_compatible: true
in productionπ Benefits & Impact
For Developers
For Organizations
For the Ecosystem
π Verification & Validation
Manual Testing Checklist
Automated Testing
Performance Testing
π Related Documentation