fix(core): add modelscope provider to handle stream_options #848
+138
−0
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.
TLDR
This pull request introduces a dedicated
ModelScopeOpenAICompatibleProviderto resolve a400 Bad Requesterror when making non-streaming API calls to ModelScope. The provider ensures API compatibility by removing thestream_optionsparameter from non-streaming requests, which was the root cause of the error. A corresponding unit test has been added to verify this behavior.Dive Deeper
The investigation into issue #840 revealed that the ModelScope API endpoint returns a
400 Bad Requestif a request payload contains thestream_optionsparameter when thestreamparameter is set tofalse. Our default OpenAI provider includedstream_optionsby default, causing all non-streaming requests to fail.This fix introduces a new
ModelScopeOpenAICompatibleProviderthat overrides thebuildRequestmethod. This overridden method inspects the request payload and explicitly deletes thestream_optionsproperty if the request is not a streaming request. ThedetermineProviderfactory function inpackages/core/src/core/openaiContentGenerator/index.tshas been updated to use this new provider when the configuredbaseUrlincludes 'modelscope'.This ensures that requests sent to ModelScope are compliant with their API specification, resolving the error while maintaining correct behavior for other OpenAI-compatible providers.
Reviewer Test Plan
A reviewer can validate this change in two ways:
Unit Tests: Run the newly added test suite for the provider, which validates the logic for removing
stream_options.npm run test -- packages/core/src/core/openaiContentGenerator/provider/modelscope.test.tsManual E2E Test (Requires ModelScope API Key):
[API ERROR: 400 STATUS CODE (NO BODY)].Testing Matrix
I have validated the changes on the following platform:
Linked issues / bugs
Fixes #840