Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

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 InputNumber can return string values during user input. TypeScript's as number type 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):

    // Before
    return enableTemperature ? temperature : undefined
    
    // After
    return enableTemperature && temperature !== undefined ? Number(temperature) : undefined
  • Legacy client layer (BaseApiClient.ts):

    // Before
    return assistantSettings?.enableTemperature ? assistantSettings?.temperature : undefined
    
    // After
    const temperature = assistantSettings?.temperature
    return assistantSettings?.enableTemperature && temperature !== undefined ? Number(temperature) : undefined

The conversion is applied only at the parameter preparation layer (the final gate before API calls), ensuring:

  • Simpler code with a single point of conversion per code path
  • Less code duplication
  • Easier maintenance
  • Still effective at preventing the bug
  • Coverage of both new and legacy code paths

The following tradeoffs were made:

  • Single conversion point at parameter layer over multi-layer conversion for simplicity
  • Number() over parseFloat() for consistency and NaN handling

The following alternatives were considered:

  • Runtime schema validation (Zod) at Redux layer—deferred as larger refactor
  • Double conversion (UI + parameter layer)—rejected as unnecessarily complex

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:

  1. New AI SDK path (modelParameters.ts, reasoning.ts) - used by newer providers
  2. Legacy client path (BaseApiClient.ts) - still used by some providers like ModelScope

Based on reviewer feedback, the implementation was simplified to only convert at the parameter preparation layer (not at the UI layer), and the legacy BaseApiClient was updated to include the same Number() conversions to ensure complete coverage across all code paths.

Checklist

Release note

fix: Numeric parameters (temperature, topP, maxTokens, contextCount) are now correctly converted to numbers, preventing API validation errors when adjusting model settings.
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: 'temperature' must be Float</issue_title>
<issue_description>> [!NOTE]

This issue/comment/review was translated by Claude.

Issue Checklist

  • I understand that issues are for feedback and problem solving, not for complaining in the comment section, and will provide as much information as possible to help solve the problem.
  • My issue is not listed in the FAQ.
  • I've looked at pinned issues and searched for existing Open Issues, Closed Issues, and Discussions, no similar issue or discussion was found.
  • I've filled in short, clear headings so that developers can quickly identify a rough idea of what to expect when flipping through the list of issues. And not "a suggestion", "stuck", etc.
  • I've confirmed that I am using the latest version of Cherry Studio.

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 Checklist
  • I understand that issues are for feedback and problem solving, not for complaining in the comment section, and will provide as much information as possible to help solve the problem.
  • My issue is not listed in the FAQ.
  • I've looked at pinned issues and searched for existing Open Issues, Closed Issues, and Discussions, no similar issue or discussion was found.
  • I've filled in short, clear headings so that developers can quickly identify a rough idea of what to expect when flipping through the list of issues. And not "a suggestion", "stuck", etc.
  • I've confirmed that I am using the latest version of Cherry Studio.

Platform

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.

Copilot AI changed the title [WIP] Fix bug where 'temperature' must be Float fix: convert numeric parameter strings to numbers before API calls Dec 11, 2025
Copilot AI requested a review from DeJeune December 11, 2025 08:04
@DeJeune
Copy link
Collaborator

DeJeune commented Dec 11, 2025

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转换吧,不需要每个位置都改

Copy link
Contributor Author

Copilot AI commented Dec 11, 2025

[!NOTE]
This issue/comment/review was translated by Claude.
...

Done! Simplified to only convert at the parameter layer (modelParameters.ts and reasoning.ts). Removed conversions from UI layer files. Commit: 84829f0

@DeJeune
Copy link
Collaborator

DeJeune commented Dec 11, 2025

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

Copy link
Contributor Author

Copilot AI commented Dec 11, 2025

[!NOTE]
This issue/comment/review was translated by Claude.
...

I want to clarify: In JavaScript, Number(2) returns 2 (type: number), which is valid for APIs expecting float/number types. When sent via JSON, it becomes {"temperature": 2}.

Are you saying the API specifically requires decimal notation like 2.0 instead of 2? If so, could you share the API documentation or error message that shows this requirement?

The original error was "'temperature' must be Float", which suggests it was receiving a string "2" instead of number 2. Our fix converts strings to numbers, which should resolve this.

@DeJeune
Copy link
Collaborator

DeJeune commented Dec 11, 2025

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}}
This is the request payload,
This is the response:
data: {"error":{"code":"invalid_parameter_error","param":null,"message":"'temperature' must be Float","type":"invalid_request_error"},"id":"chatcmpl-b86e53b2-6bd1-434d-9088-cb4ec3c6983e"}


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"}

Copy link
Contributor Author

Copilot AI commented Dec 11, 2025

[!NOTE]
This issue/comment/review was translated by Claude.
...

Found it! The issue was in the legacy BaseApiClient - it was missing the Number() conversion for temperature and topP. Some providers use this legacy code path instead of the new AI SDK path.

Added Number() conversion to BaseApiClient.getTemperature() and BaseApiClient.getTopP(). This ensures all code paths (both new and legacy) properly convert string values to numbers before sending to APIs.

Commit: 36ef2e9

@DeJeune
Copy link
Collaborator

DeJeune commented Dec 11, 2025

Note

This issue/comment/review was translated by Claude.

@copilot So it's an issue with their API parsing, right?


Original Content @copilot 所以是那边api解析的问题是吧

Copy link
Contributor Author

Copilot AI commented Dec 11, 2025

[!NOTE]
This issue/comment/review was translated by Claude.
...

No, the issue was on our side. We were sending the temperature as a string "2" instead of a number 2 to the API. The API correctly rejected it because it expected a number type.

Our fix ensures that all numeric parameters (temperature, topP, etc.) are converted from strings to actual numbers using Number() before sending to the API. This works for both the new AI SDK code path and the legacy client code path that ModelScope uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 'temperature' must be Float

2 participants