Skip to content

fix: default empty MiniMax timber weights#8120

Open
he-yufeng wants to merge 2 commits into
AstrBotDevs:masterfrom
he-yufeng:fix/minimax-empty-timber-weight
Open

fix: default empty MiniMax timber weights#8120
he-yufeng wants to merge 2 commits into
AstrBotDevs:masterfrom
he-yufeng:fix/minimax-empty-timber-weight

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

@he-yufeng he-yufeng commented May 9, 2026

Summary

  • use the default MiniMax timber-weight config when the saved field is empty
  • also handle whitespace-only values from the dashboard
  • keep valid custom timber-weight JSON unchanged

Fixes #8100.

To verify

  • python -m py_compile astrbot\core\provider\sources\minimax_tts_api_source.py tests\test_minimax_tts_api_source.py
  • python -m pytest tests\test_minimax_tts_api_source.py -q
  • python -m ruff check astrbot\core\provider\sources\minimax_tts_api_source.py tests\test_minimax_tts_api_source.py
  • git diff --check

Summary by Sourcery

Handle MiniMax TTS timber weight configuration defaults more robustly when the saved value is empty or whitespace-only.

Bug Fixes:

  • Fallback to the default MiniMax timber-weight configuration when the stored timber-weight value is empty or whitespace-only while preserving valid custom JSON values.

Tests:

  • Add unit tests covering empty, whitespace-only, and custom timber-weight configurations for the MiniMax TTS provider.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels May 9, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The default timber weight is duplicated as a raw JSON string in both the production code and tests; consider defining it once (e.g. as a Python list/dict constant that you json.dumps where needed) and reusing it to avoid drift and make changes safer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The default timber weight is duplicated as a raw JSON string in both the production code and tests; consider defining it once (e.g. as a Python list/dict constant that you `json.dumps` where needed) and reusing it to avoid drift and make changes safer.

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/sources/minimax_tts_api_source.py" line_range="42-45" />
<code_context>
-                '[{"voice_id": "Chinese (Mandarin)_Warm_Girl", "weight": 1}]',
-            ),
-        )
+        timber_weight = provider_config.get("minimax-timber-weight") or DEFAULT_TIMBER_WEIGHT
+        if isinstance(timber_weight, str) and not timber_weight.strip():
+            timber_weight = DEFAULT_TIMBER_WEIGHT
+        self.timber_weight: list[dict[str, str | int]] = json.loads(timber_weight)

         self.voice_setting: dict = {
</code_context>
<issue_to_address>
**issue (bug_risk):** json.loads may now receive non-string values from provider_config, causing runtime errors.

With this change, `provider_config.get("minimax-timber-weight")` may now return an already-parsed Python object instead of a JSON string. In that case `json.loads(timber_weight)` will raise `TypeError`. Consider either converting non-strings to a JSON string before calling `json.loads`, or skipping `json.loads` when the value is already of the expected Python type.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread astrbot/core/provider/sources/minimax_tts_api_source.py Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a default value for the minimax-timber-weight configuration and ensures that empty or whitespace-only values correctly fall back to this default. Accompanying unit tests were added to verify this behavior. Feedback suggests defining the default value as a Python list rather than a JSON string to avoid redundant parsing and refactoring the fallback logic to be more robust and idiomatic.

from ..provider import TTSProvider
from ..register import register_provider_adapter

DEFAULT_TIMBER_WEIGHT = '[{"voice_id": "Chinese (Mandarin)_Warm_Girl", "weight": 1}]'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Defining the default value as a Python object (list) instead of a JSON string avoids redundant parsing every time a provider instance is created. This is a more idiomatic approach for default configuration values.

Suggested change
DEFAULT_TIMBER_WEIGHT = '[{"voice_id": "Chinese (Mandarin)_Warm_Girl", "weight": 1}]'
DEFAULT_TIMBER_WEIGHT = [{"voice_id": "Chinese (Mandarin)_Warm_Girl", "weight": 1}]

Comment on lines +42 to +45
timber_weight = provider_config.get("minimax-timber-weight") or DEFAULT_TIMBER_WEIGHT
if isinstance(timber_weight, str) and not timber_weight.strip():
timber_weight = DEFAULT_TIMBER_WEIGHT
self.timber_weight: list[dict[str, str | int]] = json.loads(timber_weight)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for handling the default value can be simplified and made more robust. The current implementation uses a mix of or and explicit strip() checks that are partially redundant. Additionally, it might fail with a TypeError if the config value is not a string (e.g., if it was already parsed into a list by another part of the system).

By checking if the input is a non-empty string before parsing, we can safely fall back to the default list (assuming DEFAULT_TIMBER_WEIGHT is updated to a list as suggested in the other comment).

Suggested change
timber_weight = provider_config.get("minimax-timber-weight") or DEFAULT_TIMBER_WEIGHT
if isinstance(timber_weight, str) and not timber_weight.strip():
timber_weight = DEFAULT_TIMBER_WEIGHT
self.timber_weight: list[dict[str, str | int]] = json.loads(timber_weight)
raw_val = provider_config.get("minimax-timber-weight")
if isinstance(raw_val, str) and raw_val.strip():
self.timber_weight: list[dict[str, str | int]] = json.loads(raw_val)
else:
self.timber_weight: list[dict[str, str | int]] = DEFAULT_TIMBER_WEIGHT

@he-yufeng he-yufeng force-pushed the fix/minimax-empty-timber-weight branch from 55f4e81 to 2d62d89 Compare May 9, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]新增MiniMax TTS API报错

1 participant