-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Integrate with Tencent SentienceRecognition model #3851
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
Merged
zhanweizhang7
merged 1 commit into
v2
from
pr@v2@feat_integrate_with_tencent_sentience_recognition_model
Aug 14, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
apps/models_provider/impl/tencent_model_provider/credential/stt.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import traceback | ||
|
|
||
| from common import forms | ||
| from common.exception.app_exception import AppApiException | ||
| from common.forms import BaseForm, TooltipLabel | ||
| from django.utils.translation import gettext_lazy as _, gettext | ||
|
|
||
| from models_provider.base_model_provider import BaseModelCredential, ValidCode | ||
|
|
||
|
|
||
| class TencentSSTModelParams(BaseForm): | ||
| EngSerViceType = forms.SingleSelect( | ||
| TooltipLabel(_('Engine model type'), _('If not passed, the default value is 16k_zh (Chinese universal)')), | ||
| required=True, | ||
| default_value='16k_zh', | ||
| option_list=[ | ||
| {"value": "8k_zh", "label": _("Chinese telephone universal")}, | ||
| {"value": "8k_en", "label": _("English telephone universal")}, | ||
| {"value": "16k_zh", "label": _("Commonly used in Chinese")}, | ||
| {"value": "16k_zh-PY", "label": _("Chinese, English, and Guangdong")}, | ||
| {"value": "16k_zh_medical", "label": _("Chinese medical")}, | ||
| {"value": "16k_en", "label": _("English")}, | ||
| {"value": "16k_yue", "label": _("Cantonese")}, | ||
| {"value": "16k_ja", "label": _("Japanese")}, | ||
| {"value": "16k_ko", "label": _("Korean")}, | ||
| {"value": "16k_vi", "label": _("Vietnamese")}, | ||
| {"value": "16k_ms", "label": _("Malay language")}, | ||
| {"value": "16k_id", "label": _("Indonesian language")}, | ||
| {"value": "16k_fil", "label": _("Filipino language")}, | ||
| {"value": "16k_th", "label": _("Thai")}, | ||
| {"value": "16k_pt", "label": _("Portuguese")}, | ||
| {"value": "16k_tr", "label": _("Turkish")}, | ||
| {"value": "16k_ar", "label": _("Arabic")}, | ||
| {"value": "16k_es", "label": _("Spanish")}, | ||
| {"value": "16k_hi", "label": _("Hindi")}, | ||
| {"value": "16k_fr", "label": _("French")}, | ||
| {"value": "16k_de", "label": _("German")}, | ||
| {"value": "16k_zh_dialect", "label": _("Multiple dialects, supporting 23 dialects")} | ||
| ], | ||
| value_field='value', | ||
| text_field='label' | ||
| ) | ||
|
|
||
| class TencentSTTModelCredential(BaseForm, BaseModelCredential): | ||
| REQUIRED_FIELDS = ["SecretId", "SecretKey"] | ||
|
|
||
| @classmethod | ||
| def _validate_model_type(cls, model_type, provider, raise_exception=False): | ||
| if not any(mt['value'] == model_type for mt in provider.get_model_type_list()): | ||
| if raise_exception: | ||
| raise AppApiException(ValidCode.valid_error.value, | ||
| gettext('{model_type} Model type is not supported').format(model_type=model_type)) | ||
| return False | ||
| return True | ||
|
|
||
| @classmethod | ||
| def _validate_credential_fields(cls, model_credential, raise_exception=False): | ||
| missing_keys = [key for key in cls.REQUIRED_FIELDS if key not in model_credential] | ||
| if missing_keys: | ||
| if raise_exception: | ||
| raise AppApiException(ValidCode.valid_error.value, | ||
| gettext('{keys} is required').format(keys=", ".join(missing_keys))) | ||
| return False | ||
| return True | ||
|
|
||
| def is_valid(self, model_type, model_name, model_credential, model_params, provider, raise_exception=False): | ||
| if not (self._validate_model_type(model_type, provider, raise_exception) and | ||
| self._validate_credential_fields(model_credential, raise_exception)): | ||
| return False | ||
| try: | ||
| model = provider.get_model(model_type, model_name, model_credential, **model_params) | ||
| model.check_auth() | ||
| except Exception as e: | ||
| traceback.print_exc() | ||
| if raise_exception: | ||
| raise AppApiException(ValidCode.valid_error.value, | ||
| gettext( | ||
| 'Verification failed, please check whether the parameters are correct: {error}').format( | ||
| error=str(e))) | ||
| return False | ||
| return True | ||
|
|
||
| def encryption_dict(self, model): | ||
| return {**model, 'SecretKey': super().encryption(model.get('SecretKey', ''))} | ||
|
|
||
| SecretId = forms.PasswordInputField('SecretId', required=True) | ||
| SecretKey = forms.PasswordInputField('SecretKey', required=True) | ||
|
|
||
| def get_model_params_setting_form(self, model_name): | ||
| return TencentSSTModelParams() | ||
Binary file added
BIN
+17.5 KB
apps/models_provider/impl/tencent_model_provider/model/iat_mp3_16k.mp3
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code looks mostly clean and well-structured, but there are a few suggestions for optimization and improvement:
Comments: While comments can help clarify complex parts of the code, they should be concise and relevant to the functionality being described. You might want to remove comments that do not add significant explanation.
Redundant
gettextCalls: The method_validate_model_typecallsgettextmultiple times unnecessarily inside its body. Consider creating a helper function to handle localized strings and call it once at the start instead.Exception Handling in Model Initialization: In the
__init__method (if this is present), you might consider wrapping exception handling around the initialization of parent classes to ensure robustness. This is optional based on the context.Unused Methods: Ensure that all methods are necessary and contribute to the overall functionality. If methods like
_validate_model_typeare never called after creation, they may be candidates for removal or refactoring into utility functions.Field Validation Logic: There's no explicit validation logic for fields within each form field. However, assuming these fields have default values, ensuring valid data types or ranges would improve robustness.
Here’s an optimized version of your code with some minor adjustments:
This revised version aims to simplify repeated operations such as validating fields and improving readability through the use of more descriptive variable names and function definitions where applicable.