Skip to content

Add MiniMax music generation tool#359

Merged
ModerRAS merged 2 commits into
masterfrom
codex/add-minimax-music-tool
May 31, 2026
Merged

Add MiniMax music generation tool#359
ModerRAS merged 2 commits into
masterfrom
codex/add-minimax-music-tool

Conversation

@ModerRAS
Copy link
Copy Markdown
Owner

@ModerRAS ModerRAS commented May 31, 2026

Summary

  • add a built-in generate_music tool backed by MiniMax /v1/music_generation
  • add music-generation model capability discovery and group/default model configuration commands
  • persist generated audio locally and send it back to the active Telegram chat after tool completion
  • document the new tool and add focused unit coverage

Validation

  • dotnet build TelegramSearchBot.sln --configuration Debug
  • dotnet test TelegramSearchBot.Test\TelegramSearchBot.Test.csproj --configuration Debug --no-build --filter "FullyQualifiedNameMusicGenerationToolServiceTests|FullyQualifiedNameImageGenerationToolServiceTests|FullyQualifiedName~EditLLMConfTest"
  • dotnet test TelegramSearchBot.LLM.Test\TelegramSearchBot.LLM.Test.csproj --configuration Debug --no-build --filter "FullyQualifiedNameModelCapabilityServiceTests|FullyQualifiedNameModelWithCapabilitiesTests"
  • git diff --check

Summary by CodeRabbit

  • New Features
    • Music generation tool now available with built-in command support for generating audio
    • Admin commands to enable/disable the music generation tool
    • Configurable default music generation models at the group level
    • Model selection across multiple channels and providers
    • Customizable audio output formats, sample rates, and delivery options

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

Warning

Review limit reached

@ModerRAS, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 12 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 42fb668f-884d-48a9-8201-8d378f31880d

📥 Commits

Reviewing files that changed from the base of the PR and between 2776a09 and 338d255.

📒 Files selected for processing (3)
  • Docs/README_MCP.md
  • TelegramSearchBot.LLM/Service/AI/LLM/ModelCapabilityService.cs
  • TelegramSearchBot/Service/Tools/MusicGenerationToolService.cs
📝 Walkthrough

Walkthrough

This PR adds a complete music generation feature to a Telegram bot using MiniMax API. It includes model capability detection, database schema for per-chat overrides, a comprehensive tool service handling MiniMax integration and Telegram delivery, admin commands for configuration, startup initialization, and documentation.

Changes

Music Generation Tool Feature

Layer / File(s) Summary
Model capability detection for music generation
TelegramSearchBot.Common/Model/AI/ModelWithCapabilities.cs, TelegramSearchBot.LLM/Interface/IModelCapabilityService.cs, TelegramSearchBot.LLM/Service/AI/LLM/ModelCapabilityService.cs, TelegramSearchBot.LLM.Test/Service/AI/LLM/*
Added SupportsMusicGeneration property and IsKnownMusicGenerationModelName() to identify music models via capability flags or known names. Service method GetMusicGenerationModels() queries all music-capable models with tests validating capability and name-based detection.
Database schema for music model storage
TelegramSearchBot.Database/Model/Data/GroupSettings.cs, TelegramSearchBot.Database/Migrations/*
Added MusicGenerationModelName column to GroupSettings table to support per-chat model overrides, with EF Core migration and model snapshot updates.
Music generation result data models
TelegramSearchBot.Common/Model/Tools/MusicGenerationResult.cs
Defined MusicGenerationResult, GeneratedMusicInfo, and SendAudioResult classes for generation outcomes and Telegram delivery metadata.
Music generation tool service implementation
TelegramSearchBot/Service/Tools/MusicGenerationToolService.cs, TelegramSearchBot.Test/Service/Tools/MusicGenerationToolServiceTests.cs
Implemented MusicGenerationToolSettingsService for configuration management (enable/disable, default and per-chat models). Implemented MusicGenerationToolService with MiniMax integration: parameter validation/normalization, request construction, concurrency limiting via Redis semaphores, audio persistence, Telegram delivery (as audio or document), plus extensive helpers for response parsing, validation, and format mapping. Comprehensive tests cover endpoint normalization, text-to-music and cover generation constraints, response handling, and model precedence.
Admin user commands for music model management
TelegramSearchBot/Controller/AI/LLM/GeneralLLMController.cs
Added commands for normal admins: list available music models, select/set per-chat model overrides, clear overrides, and view current settings. Implemented Redis-backed selection workflow with numeric indexing and cancellation support.
Global admin configuration for music tool
TelegramSearchBot/Model/AI/LLMConfState.cs, TelegramSearchBot/Service/Manage/EditLLMConfService.cs, TelegramSearchBot.Test/Manage/EditLLMConfTest.cs
Added SettingMusicGenerationModel enum state and handler to enable/disable music tool globally and set default model via stateful Redis interaction.
Startup and service integration
TelegramSearchBot/AppBootstrap/GeneralBootstrap.cs, TelegramSearchBot/Service/Tools/ImageGenerationToolService.cs
Initialized MusicGenerationToolSettingsService during app startup. Updated ImageGenerationToolService attribute for consistency.
Documentation updates
Docs/Bot_Commands_User_Guide.md, Docs/Existing_Codebase_Overview.md, Docs/README_MCP.md, Docs/README_ModelCapabilities.md, TelegramSearchBot/Controller/Help/HelpController.cs
Documented music generation tool parameters, admin commands, MiniMax configuration, model identification rules, and updated user-facing help text.

Sequence Diagram

sequenceDiagram
  participant Admin as Admin User
  participant Controller as GeneralLLMController
  participant Settings as MusicGenerationToolSettingsService
  participant Service as MusicGenerationToolService
  participant MiniMax as MiniMax API
  participant Telegram as Telegram Bot
  
  Admin->>Controller: /选择音乐模型 (choose model)
  Controller->>Service: LoadMusicGenerationModelOptionsAsync()
  Service->>Service: GetMusicGenerationModels()
  Service-->>Controller: List of available models
  Controller->>Admin: Show model selection menu
  Admin->>Controller: Select model by number
  Controller->>Settings: SetGroupModelNameAsync(chatId, model)
  Settings->>Settings: Update GroupSettings
  Settings-->>Controller: Success
  Controller->>Admin: Model set confirmation
  
  Note over Admin,Telegram: Later, when model is invoked...
  Admin->>Controller: Generate music via /generate_music
  Controller->>Service: GenerateMusic(prompt, ...)
  Service->>Settings: GetModelNameAsync(chatId)
  Settings-->>Service: Group model or default
  Service->>MiniMax: POST music_generation request
  MiniMax-->>Service: Audio (URL or hex bytes)
  Service->>Service: Save audio file
  Service->>Telegram: Send audio to chat
  Telegram-->>Service: MessageId
  Service-->>Controller: MusicGenerationResult
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 A melody born from the code so bright,
MiniMax tunes dancing through bytes of light,
Redis-backed choices for every chat,
Music flows freely—how grand is that!
🎵🎶✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.80% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add MiniMax music generation tool' clearly and specifically describes the main change: adding a new music generation tool feature backed by MiniMax. It accurately reflects the primary objective of this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/add-minimax-music-tool

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 31, 2026

PR Check Report

Summary

Test Results

Platform Status Details
Ubuntu Passed Tests passed, artifacts uploaded
Windows Passed Tests passed, artifacts uploaded

Code Quality

  • Code formatting check
  • Security vulnerability scan
  • Dependency analysis
  • Code coverage collection

Test Artifacts

  • Test results artifacts count: 2
  • Code coverage uploaded to Codecov

Links


This report is auto-generated by GitHub Actions

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
TelegramSearchBot/Controller/Help/HelpController.cs (1)

27-52: ⚡ Quick win

Avoid duplicating command docs in hardcoded strings.

helpText now carries another growing command list in code, which will keep drifting from Docs/Bot_Commands_User_Guide.md. Consider loading/templating help content from one source to reduce future inconsistencies.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@TelegramSearchBot/Controller/Help/HelpController.cs` around lines 27 - 52,
The hardcoded helpText string in HelpController (variable helpText) duplicates
documentation and will diverge from Docs/Bot_Commands_User_Guide.md; replace the
inline literal with code that reads/loads the canonical help content (e.g., read
the markdown file Docs/Bot_Commands_User_Guide.md or use a shared template
service) at startup or on-demand and assign it to helpText, falling back to a
small default message if the file is missing, and ensure any formatting/encoding
is preserved when returning the help text.
TelegramSearchBot.Test/Manage/EditLLMConfTest.cs (1)

119-126: ⚖️ Poor tradeoff

Consider adding test coverage for music tool configuration flows.

The test setup correctly wires MusicGenerationToolSettingsService, but no new test methods were added to verify the music-specific functionality introduced in EditLLMConfService:

  • Music tool enable/disable commands
  • Music tool status query
  • Setting default music model via state machine
  • Music model state handler (HandleSettingMusicGenerationModelAsync)

Adding test coverage similar to the existing tests (e.g., ExecuteAsync_SetMaxRetryCount) would help catch regressions in the music configuration flows.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@TelegramSearchBot.Test/Manage/EditLLMConfTest.cs` around lines 119 - 126, Add
unit tests covering the music tool configuration flows introduced in
EditLLMConfService: write tests that use the existing test harness (with
MusicGenerationToolSettingsService already wired) to verify enable/disable
commands for the music tool, the music tool status query, setting the default
music model via the state machine, and the state handler
HandleSettingMusicGenerationModelAsync; mirror the style of existing tests such
as ExecuteAsync_SetMaxRetryCount to assert command handling, state transitions,
and persisted settings changes in the MusicGenerationToolSettingsService and
EditLLMConfService interactions.
TelegramSearchBot/Controller/AI/LLM/GeneralLLMController.cs (1)

401-436: 💤 Low value

Consider refactoring duplicated model selection logic.

The music model selection methods (lines 401-436, 458-476, 485-490, 508-522, 528-533) are nearly identical to the image model selection methods (lines 364-399, 438-456, 478-483, 492-506, 524-526). The only differences are the service reference, Redis key prefix, and user-facing strings.

While the current implementation is correct and follows the established pattern, consolidating this logic into a generic helper (e.g., ModelSelectionHelper<TService, TOption>) would reduce maintenance burden and prevent divergence.

Also applies to: 458-476, 485-490, 508-522, 528-533

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@TelegramSearchBot/Controller/AI/LLM/GeneralLLMController.cs` around lines 401
- 436, The music vs image model selection handlers duplicate the same flow
(checking Redis key, parsing index/取消, validating range, calling
SetGroupModelNameAsync, clearing key, logging and sending messages); factor this
into a single reusable helper (e.g.,
ModelSelectionHelper.HandlePendingSelectionAsync) that accepts the Redis key
generator (GetMusicGenerationModelSelectionKey / image equivalent), the service
caller delegate (Func<long, string, Task<(string previous, string current)>> or
an interface method wrapper to call SetGroupModelNameAsync on
IMusicGenerationToolSettingsService/ IImageGenerationToolSettingsService), the
localized prompt/result strings, and required dependencies (IDatabase from
_connectionMultiplexer, SendMessageService, logger). Replace
TryHandlePendingMusicGenerationModelSelectionAsync and the image methods with
thin wrappers that construct the key, choose messages and service delegate, then
call the generic handler; ensure the helper preserves existing behaviors
(trim/parse/取消, range checks, key deletion, log message using
telegramMessage.Chat.Id and MessageId).
TelegramSearchBot.LLM/Service/AI/LLM/ModelCapabilityService.cs (1)

189-199: 💤 Low value

Redundant MiniMax branch — names already covered.

IsKnownMusicGenerationModelName (Line 193) already matches music-2.6, music-2.6-free, music-cover, and music-cover-free case-insensitively for any provider, so the MiniMax-specific check on Lines 194-198 is dead code. It mirrors the existing image record helper, so this is a non-blocking cleanup; safe to drop the branch (or keep it intentionally if you expect the known-name list and MiniMax list to diverge later).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@TelegramSearchBot.LLM/Service/AI/LLM/ModelCapabilityService.cs` around lines
189 - 199, The IsMusicGenerationModelRecord method contains a redundant
MiniMax-specific branch: remove the trailing condition that checks
model.LLMChannel?.Provider == LLMProvider.MiniMax and the explicit
model.ModelName comparisons ("music-2.6", "music-2.6-free", "music-cover",
"music-cover-free") because
ModelWithCapabilities.IsKnownMusicGenerationModelName(model.ModelName) already
covers those names case-insensitively for any provider; update
IsMusicGenerationModelRecord to rely on the capability checks and
IsKnownMusicGenerationModelName only, leaving the provider-specific branch out
(or delete that clause) to eliminate dead code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Docs/README_MCP.md`:
- Around line 76-90: The docs mix camelCase and snake_case for the
generate_music tool parameters which breaks real calls; pick the canonical
naming used by the tool schema and make all parameter names consistent (e.g., if
the tool expects snake_case, change lyricsOptimizer->lyrics_optimizer,
audioUrl->audio_url, audioBase64->audio_base64, isInstrumental->is_instrumental,
outputFormat->output_format, sampleRate->sample_rate, bitrate->bitrate,
format->format, aigcWatermark->aigc_watermark, coverFeatureId->cover_feature_id,
sendToChat->send_to_chat, replyToMessageId->reply_to_message_id,
timeoutSeconds->timeout_seconds, etc.), update the example/parameter table and
any descriptive text referencing these fields, and ensure the README_MCP.md
generate_music parameter list exactly matches the actual tool schema used by the
implementation.

In `@TelegramSearchBot/Service/Tools/MusicGenerationToolService.cs`:
- Around line 414-426: TryAcquireChannelAsync currently uses a non-atomic
check-then-increment on Redis (reading key via redisDb.StringGetAsync and then
StringIncrementAsync) which allows a race and can exceed channel.Parallel;
replace this with an atomic Lua script executed via ScriptEvaluateAsync that
takes GetSemaphoreKey(channel.Id) as KEYS[1] and channel.Parallel (use
Math.Max(1, channel.Parallel)) as ARGV[1], checks GET or 0, INCRs only when
current < limit and returns success/failure; update TryAcquireChannelAsync to
call ScriptEvaluateAsync, interpret the numeric result as bool, and keep
references to _connectionMultiplexer and GetSemaphoreKey to locate the code to
change.

---

Nitpick comments:
In `@TelegramSearchBot.LLM/Service/AI/LLM/ModelCapabilityService.cs`:
- Around line 189-199: The IsMusicGenerationModelRecord method contains a
redundant MiniMax-specific branch: remove the trailing condition that checks
model.LLMChannel?.Provider == LLMProvider.MiniMax and the explicit
model.ModelName comparisons ("music-2.6", "music-2.6-free", "music-cover",
"music-cover-free") because
ModelWithCapabilities.IsKnownMusicGenerationModelName(model.ModelName) already
covers those names case-insensitively for any provider; update
IsMusicGenerationModelRecord to rely on the capability checks and
IsKnownMusicGenerationModelName only, leaving the provider-specific branch out
(or delete that clause) to eliminate dead code.

In `@TelegramSearchBot.Test/Manage/EditLLMConfTest.cs`:
- Around line 119-126: Add unit tests covering the music tool configuration
flows introduced in EditLLMConfService: write tests that use the existing test
harness (with MusicGenerationToolSettingsService already wired) to verify
enable/disable commands for the music tool, the music tool status query, setting
the default music model via the state machine, and the state handler
HandleSettingMusicGenerationModelAsync; mirror the style of existing tests such
as ExecuteAsync_SetMaxRetryCount to assert command handling, state transitions,
and persisted settings changes in the MusicGenerationToolSettingsService and
EditLLMConfService interactions.

In `@TelegramSearchBot/Controller/AI/LLM/GeneralLLMController.cs`:
- Around line 401-436: The music vs image model selection handlers duplicate the
same flow (checking Redis key, parsing index/取消, validating range, calling
SetGroupModelNameAsync, clearing key, logging and sending messages); factor this
into a single reusable helper (e.g.,
ModelSelectionHelper.HandlePendingSelectionAsync) that accepts the Redis key
generator (GetMusicGenerationModelSelectionKey / image equivalent), the service
caller delegate (Func<long, string, Task<(string previous, string current)>> or
an interface method wrapper to call SetGroupModelNameAsync on
IMusicGenerationToolSettingsService/ IImageGenerationToolSettingsService), the
localized prompt/result strings, and required dependencies (IDatabase from
_connectionMultiplexer, SendMessageService, logger). Replace
TryHandlePendingMusicGenerationModelSelectionAsync and the image methods with
thin wrappers that construct the key, choose messages and service delegate, then
call the generic handler; ensure the helper preserves existing behaviors
(trim/parse/取消, range checks, key deletion, log message using
telegramMessage.Chat.Id and MessageId).

In `@TelegramSearchBot/Controller/Help/HelpController.cs`:
- Around line 27-52: The hardcoded helpText string in HelpController (variable
helpText) duplicates documentation and will diverge from
Docs/Bot_Commands_User_Guide.md; replace the inline literal with code that
reads/loads the canonical help content (e.g., read the markdown file
Docs/Bot_Commands_User_Guide.md or use a shared template service) at startup or
on-demand and assign it to helpText, falling back to a small default message if
the file is missing, and ensure any formatting/encoding is preserved when
returning the help text.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0179e40b-5366-4348-b26d-482d16b87f99

📥 Commits

Reviewing files that changed from the base of the PR and between b853a2e and 2776a09.

📒 Files selected for processing (23)
  • Docs/Bot_Commands_User_Guide.md
  • Docs/Existing_Codebase_Overview.md
  • Docs/README_MCP.md
  • Docs/README_ModelCapabilities.md
  • TelegramSearchBot.Common/Model/AI/ModelWithCapabilities.cs
  • TelegramSearchBot.Common/Model/Tools/MusicGenerationResult.cs
  • TelegramSearchBot.Database/Migrations/20260531090000_AddGroupMusicGenerationModel.Designer.cs
  • TelegramSearchBot.Database/Migrations/20260531090000_AddGroupMusicGenerationModel.cs
  • TelegramSearchBot.Database/Migrations/DataDbContextModelSnapshot.cs
  • TelegramSearchBot.Database/Model/Data/GroupSettings.cs
  • TelegramSearchBot.LLM.Test/Service/AI/LLM/ModelCapabilityServiceTests.cs
  • TelegramSearchBot.LLM.Test/Service/AI/LLM/ModelWithCapabilitiesTests.cs
  • TelegramSearchBot.LLM/Interface/IModelCapabilityService.cs
  • TelegramSearchBot.LLM/Service/AI/LLM/ModelCapabilityService.cs
  • TelegramSearchBot.Test/Manage/EditLLMConfTest.cs
  • TelegramSearchBot.Test/Service/Tools/MusicGenerationToolServiceTests.cs
  • TelegramSearchBot/AppBootstrap/GeneralBootstrap.cs
  • TelegramSearchBot/Controller/AI/LLM/GeneralLLMController.cs
  • TelegramSearchBot/Controller/Help/HelpController.cs
  • TelegramSearchBot/Model/AI/LLMConfState.cs
  • TelegramSearchBot/Service/Manage/EditLLMConfService.cs
  • TelegramSearchBot/Service/Tools/ImageGenerationToolService.cs
  • TelegramSearchBot/Service/Tools/MusicGenerationToolService.cs

Comment thread Docs/README_MCP.md
Comment thread TelegramSearchBot/Service/Tools/MusicGenerationToolService.cs
@ModerRAS ModerRAS merged commit 24c9b98 into master May 31, 2026
5 checks passed
@ModerRAS ModerRAS deleted the codex/add-minimax-music-tool branch May 31, 2026 11:24
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.

1 participant