Skip to content

[feature] add FunASRNano config into golang api - #2974

Merged
csukuangfj merged 2 commits into
k2-fsa:masterfrom
ilibx:master
Jan 4, 2026
Merged

csukuangfj merged 2 commits into
k2-fsa:masterfrom
ilibx:master

Conversation

@ilibx

@ilibx ilibx commented Jan 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • New Features
    • Added support for FunASRNano model configuration for offline speech recognition with customizable encoder adaptation, language model components, embeddings, and tokenizer settings.
    • Introduced new configuration options for generation parameters including temperature, sampling probability, and seed control.

✏️ Tip: You can customize this high-level summary in your review settings.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 4, 2026
@coderabbitai

coderabbitai Bot commented Jan 4, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@ilibx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5d9610b and 799b162.

📒 Files selected for processing (1)
  • scripts/go/sherpa_onnx.go

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Added a new OfflineFunASRNanoModelConfig struct type to support FunASR Nano model configuration in the Go sherpa-onnx bindings. Extended OfflineModelConfig with a FunASRNano field and integrated the configuration into the offline recognizer's C struct population and cleanup routines.

Changes

Cohort / File(s) Summary
FunASR Nano Configuration
scripts/go/sherpa_onnx.go
Added new OfflineFunASRNanoModelConfig struct with 11 fields (encoder/decoder paths, embedding, tokenizer, prompts, sampling parameters). Integrated FunASRNano field into OfflineModelConfig. Wired configuration into offline recognizer C struct population and cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A nano model takes its place,
New configs with elegant grace!
FunASR hops into the fray,
Encoders and prompts light the way,
Sherpa's roster grows each day! 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add FunASRNano config into golang api' clearly and concisely describes the main change: adding a new FunASRNano configuration type and field to the Go API.

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.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @ilibx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request extends the Go API by adding comprehensive support for the FunASRNano model. It introduces a dedicated configuration structure for FunASRNano, integrates it into the existing offline model configuration, and provides the necessary C-binding logic for both initialization and memory management. This enhancement allows users to configure and utilize the FunASRNano model with its specific parameters directly through the Go interface.

Highlights

  • New Model Configuration: Introduced a new OfflineFunASRNanoModelConfig struct to define specific configuration parameters for the FunASRNano model, including various LLM and prompt-related settings.
  • API Integration: Integrated the FunASRNano configuration into the main OfflineModelConfig struct, making it accessible within the Go API's overall model configuration.
  • C-Binding Initialization: Added logic within newCOfflineRecognizerConfig to correctly initialize the C-level funasr_nano configuration fields from the new Go struct, handling string conversions and numeric assignments.
  • Memory Management: Implemented corresponding memory deallocation for the FunASRNano C-struct fields in freeCOfflineRecognizerConfig to ensure proper resource cleanup and prevent memory leaks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb941f5 and 5d9610b.

📒 Files selected for processing (1)
  • scripts/go/sherpa_onnx.go
🧰 Additional context used
🧬 Code graph analysis (1)
scripts/go/sherpa_onnx.go (1)
sherpa-onnx/c-api/cxx-api.h (1)
  • OfflineFunASRNanoModelConfig (286-298)
🔇 Additional comments (3)
scripts/go/sherpa_onnx.go (3)

501-501: LGTM!

The field addition follows the established pattern and naming conventions.


600-610: LGTM!

The C struct population follows the established pattern. All 11 fields are correctly populated with appropriate type conversions, and memory management is consistent with the cleanup in freeCOfflineRecognizerConfig.


743-776: LGTM!

The cleanup logic correctly frees all 7 string fields allocated during config construction. The nil checks and pointer resets follow best practices and are consistent with the rest of the file.

Comment thread scripts/go/sherpa_onnx.go
Comment on lines +455 to +467
type OfflineFunASRNanoModelConfig struct {
EncoderAdaptor string
LlmPreFill string
LlmDecoder string
Embedding string
Tokenizer string
SystemPrompt string
UserPrompt string
MaxNewTokens int
Temperature float32
TopP float32
Seed int32
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Type inconsistency: MaxNewTokens should be int32.

The MaxNewTokens field is declared as int, but according to the C API reference (line 297 in cxx-api.h), it should be int32_t. For consistency with the C API and with the Seed field (which is correctly typed as int32), change MaxNewTokens to int32.

🔎 Proposed fix
 type OfflineFunASRNanoModelConfig struct {
 	EncoderAdaptor string
 	LlmPreFill     string
 	LlmDecoder     string
 	Embedding      string
 	Tokenizer      string
 	SystemPrompt   string
 	UserPrompt     string
-	MaxNewTokens   int
+	MaxNewTokens   int32
 	Temperature    float32
 	TopP           float32
 	Seed           int32
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type OfflineFunASRNanoModelConfig struct {
EncoderAdaptor string
LlmPreFill string
LlmDecoder string
Embedding string
Tokenizer string
SystemPrompt string
UserPrompt string
MaxNewTokens int
Temperature float32
TopP float32
Seed int32
}
type OfflineFunASRNanoModelConfig struct {
EncoderAdaptor string
LlmPreFill string
LlmDecoder string
Embedding string
Tokenizer string
SystemPrompt string
UserPrompt string
MaxNewTokens int32
Temperature float32
TopP float32
Seed int32
}
🤖 Prompt for AI Agents
In scripts/go/sherpa_onnx.go around lines 455 to 467, the struct field
MaxNewTokens is declared as int but the C API expects int32_t; change the
MaxNewTokens type to int32 to match the C API and keep consistency with the Seed
field, updating any usages or conversions where this field is set or passed to
ensure proper int32 handling.

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

Copy link
Copy Markdown

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 adds the configuration for FunASRNano to the Go API. The changes are well-contained and follow the existing structure for adding new model configurations. I've identified a minor type inconsistency in the new configuration struct and an opportunity to refactor some repetitive code to improve maintainability. Overall, the changes look good.

Comment thread scripts/go/sherpa_onnx.go
Tokenizer string
SystemPrompt string
UserPrompt string
MaxNewTokens int

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency with the Seed field (which is int32) and the corresponding C++ type int32_t, it's better to define MaxNewTokens as int32 instead of int. This ensures type safety and avoids potential issues on different architectures where int might have a different size.

Suggested change
MaxNewTokens int
MaxNewTokens int32

Comment thread scripts/go/sherpa_onnx.go
Comment on lines +743 to +776
if c.model_config.funasr_nano.encoder_adaptor != nil {
C.free(unsafe.Pointer(c.model_config.funasr_nano.encoder_adaptor))
c.model_config.funasr_nano.encoder_adaptor = nil
}

if c.model_config.funasr_nano.llm_prefill != nil {
C.free(unsafe.Pointer(c.model_config.funasr_nano.llm_prefill))
c.model_config.funasr_nano.llm_prefill = nil
}

if c.model_config.funasr_nano.llm_decode != nil {
C.free(unsafe.Pointer(c.model_config.funasr_nano.llm_decode))
c.model_config.funasr_nano.llm_decode = nil
}

if c.model_config.funasr_nano.embedding != nil {
C.free(unsafe.Pointer(c.model_config.funasr_nano.embedding))
c.model_config.funasr_nano.embedding = nil
}

if c.model_config.funasr_nano.tokenizer != nil {
C.free(unsafe.Pointer(c.model_config.funasr_nano.tokenizer))
c.model_config.funasr_nano.tokenizer = nil
}

if c.model_config.funasr_nano.system_prompt != nil {
C.free(unsafe.Pointer(c.model_config.funasr_nano.system_prompt))
c.model_config.funasr_nano.system_prompt = nil
}

if c.model_config.funasr_nano.user_prompt != nil {
C.free(unsafe.Pointer(c.model_config.funasr_nano.user_prompt))
c.model_config.funasr_nano.user_prompt = nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This block of code for freeing C strings is quite repetitive. You can refactor it to reduce duplication and improve maintainability by iterating over a slice of pointers to the string fields.

stringFields := []*(*C.char){
		&c.model_config.funasr_nano.encoder_adaptor,
		&c.model_config.funasr_nano.llm_prefill,
		&c.model_config.funasr_nano.llm_decode,
		&c.model_config.funasr_nano.embedding,
		&c.model_config.funasr_nano.tokenizer,
		&c.model_config.funasr_nano.system_prompt,
		&c.model_config.funasr_nano.user_prompt,
	}

	for _, field := range stringFields {
		if *field != nil {
			C.free(unsafe.Pointer(*field))
			*field = nil
		}
	}

Comment thread scripts/go/sherpa_onnx.go Outdated
MaxNewTokens int
Temperature float32
TopP float32
Seed int32

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use int, not int32 in Go.

@csukuangfj

Copy link
Copy Markdown
Collaborator

Thank you for your contribution!

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants