Skip to content

Commit f9f475a

Browse files
committed
feat: Integrate with Tencent SentienceRecognition model
1 parent 8ee9bc0 commit f9f475a

File tree

9 files changed

+418
-4
lines changed

9 files changed

+418
-4
lines changed

apps/locales/en_US/LC_MESSAGES/django.po

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8570,4 +8570,82 @@ msgid "Edit user authorization status of resource"
85708570
msgstr ""
85718571

85728572
msgid "Get user authorization status of resource by page"
8573+
msgstr ""
8574+
8575+
msgid "Obtain resource authorization list by page"
8576+
msgstr ""
8577+
8578+
msgid "Engine model type"
8579+
msgstr ""
8580+
8581+
msgid "If not passed, the default value is 16k_zh (Chinese universal)"
8582+
msgstr ""
8583+
8584+
msgid "Chinese telephone universal"
8585+
msgstr ""
8586+
8587+
msgid "English telephone universal"
8588+
msgstr ""
8589+
8590+
msgid "Commonly used in Chinese"
8591+
msgstr ""
8592+
8593+
msgid "Chinese, English, and Guangdong"
8594+
msgstr ""
8595+
8596+
msgid "Chinese medical"
8597+
msgstr ""
8598+
8599+
msgid "English"
8600+
msgstr ""
8601+
8602+
msgid "Cantonese"
8603+
msgstr ""
8604+
8605+
msgid "Japanese"
8606+
msgstr ""
8607+
8608+
msgid "Korean"
8609+
msgstr ""
8610+
8611+
msgid "Vietnamese"
8612+
msgstr ""
8613+
8614+
msgid "Malay language"
8615+
msgstr ""
8616+
8617+
msgid "Indonesian language"
8618+
msgstr ""
8619+
8620+
msgid "Filipino language"
8621+
msgstr ""
8622+
8623+
msgid "Thai"
8624+
msgstr ""
8625+
8626+
msgid "Portuguese"
8627+
msgstr ""
8628+
8629+
msgid "Turkish"
8630+
msgstr ""
8631+
8632+
msgid "Arabic"
8633+
msgstr ""
8634+
8635+
msgid "Spanish"
8636+
msgstr ""
8637+
8638+
msgid "Hindi"
8639+
msgstr ""
8640+
8641+
msgid "French"
8642+
msgstr ""
8643+
8644+
msgid "German"
8645+
msgstr ""
8646+
8647+
msgid "Multiple dialects, supporting 23 dialects"
8648+
msgstr ""
8649+
8650+
msgid "This interface is used to recognize short audio files within 60 seconds. Supports Mandarin Chinese, English, Cantonese, Japanese, Vietnamese, Malay, Indonesian, Filipino, Thai, Portuguese, Turkish, Arabic, Hindi, French, German, and 23 Chinese dialects."
85738651
msgstr ""

apps/locales/zh_CN/LC_MESSAGES/django.po

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8696,4 +8696,82 @@ msgid "Edit user authorization status of resource"
86968696
msgstr "修改资源对用户的授权状态"
86978697

86988698
msgid "Get user authorization status of resource by page"
8699-
msgstr "分页获取资源对用户的授权状态"
8699+
msgstr "分页获取资源对用户的授权状态"
8700+
8701+
msgid "Obtain resource authorization list by page"
8702+
msgstr "分页获取资源授权列表"
8703+
8704+
msgid "Engine model type"
8705+
msgstr "引擎模型类型"
8706+
8707+
msgid "If not passed, the default value is 16k_zh (Chinese universal)"
8708+
msgstr "如果未传递,默认值为 16k_zh(中文通用)"
8709+
8710+
msgid "Chinese telephone universal"
8711+
msgstr "中文电话通用"
8712+
8713+
msgid "English telephone universal"
8714+
msgstr "英文电话通用"
8715+
8716+
msgid "Commonly used in Chinese"
8717+
msgstr "中文常用"
8718+
8719+
msgid "Chinese, English, and Guangdong"
8720+
msgstr "中文、英文和广东话"
8721+
8722+
msgid "Chinese medical"
8723+
msgstr "中文医疗"
8724+
8725+
msgid "English"
8726+
msgstr "英文"
8727+
8728+
msgid "Cantonese"
8729+
msgstr "粤语"
8730+
8731+
msgid "Japanese"
8732+
msgstr "日语"
8733+
8734+
msgid "Korean"
8735+
msgstr "韩语"
8736+
8737+
msgid "Vietnamese"
8738+
msgstr "越南语"
8739+
8740+
msgid "Malay language"
8741+
msgstr "马来语"
8742+
8743+
msgid "Indonesian language"
8744+
msgstr "印尼语"
8745+
8746+
msgid "Filipino language"
8747+
msgstr "菲律宾语"
8748+
8749+
msgid "Thai"
8750+
msgstr "泰语"
8751+
8752+
msgid "Portuguese"
8753+
msgstr "葡萄牙语"
8754+
8755+
msgid "Turkish"
8756+
msgstr "土耳其语"
8757+
8758+
msgid "Arabic"
8759+
msgstr "阿拉伯语"
8760+
8761+
msgid "Spanish"
8762+
msgstr "西班牙语"
8763+
8764+
msgid "Hindi"
8765+
msgstr "印地语"
8766+
8767+
msgid "French"
8768+
msgstr "法语"
8769+
8770+
msgid "German"
8771+
msgstr "德语"
8772+
8773+
msgid "Multiple dialects, supporting 23 dialects"
8774+
msgstr "多种方言,支持 23 种方言"
8775+
8776+
msgid "This interface is used to recognize short audio files within 60 seconds. Supports Mandarin Chinese, English, Cantonese, Japanese, Vietnamese, Malay, Indonesian, Filipino, Thai, Portuguese, Turkish, Arabic, Hindi, French, German, and 23 Chinese dialects."
8777+
msgstr "本接口用于识别 60 秒之内的短音频文件。支持中文普通话、英语、粤语、日语、越南语、马来语、印度尼西亚语、菲律宾语、泰语、葡萄牙语、土耳其语、阿拉伯语、印地语、法语、德语及 23 种汉语方言。"

apps/locales/zh_Hant/LC_MESSAGES/django.po

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8696,4 +8696,82 @@ msgid "Edit user authorization status of resource"
86968696
msgstr "修改資源對用戶的授權狀態"
86978697

86988698
msgid "Get user authorization status of resource by page"
8699-
msgstr "分頁獲取資源對用戶的授權狀態"
8699+
msgstr "分頁獲取資源對用戶的授權狀態"
8700+
8701+
msgid "Obtain resource authorization list by page"
8702+
msgstr "分頁獲取資源授權清單"
8703+
8704+
msgid "Engine model type"
8705+
msgstr "引擎模型類型"
8706+
8707+
msgid "If not passed, the default value is 16k_zh (Chinese universal)"
8708+
msgstr "如果未傳遞,默認值為 16k_zh(中文通用)"
8709+
8710+
msgid "Chinese telephone universal"
8711+
msgstr "中文電話通用"
8712+
8713+
msgid "English telephone universal"
8714+
msgstr "英文電話通用"
8715+
8716+
msgid "Commonly used in Chinese"
8717+
msgstr "中文常用"
8718+
8719+
msgid "Chinese, English, and Guangdong"
8720+
msgstr "中文、英文和廣東話"
8721+
8722+
msgid "Chinese medical"
8723+
msgstr "中文醫療"
8724+
8725+
msgid "English"
8726+
msgstr "英文"
8727+
8728+
msgid "Cantonese"
8729+
msgstr "粵語"
8730+
8731+
msgid "Japanese"
8732+
msgstr "日語"
8733+
8734+
msgid "Korean"
8735+
msgstr "韓語"
8736+
8737+
msgid "Vietnamese"
8738+
msgstr "越南語"
8739+
8740+
msgid "Malay language"
8741+
msgstr "馬來語"
8742+
8743+
msgid "Indonesian language"
8744+
msgstr "印尼語"
8745+
8746+
msgid "Filipino language"
8747+
msgstr "菲律賓語"
8748+
8749+
msgid "Thai"
8750+
msgstr "泰語"
8751+
8752+
msgid "Portuguese"
8753+
msgstr "葡萄牙語"
8754+
8755+
msgid "Turkish"
8756+
msgstr "土耳其語"
8757+
8758+
msgid "Arabic"
8759+
msgstr "阿拉伯語"
8760+
8761+
msgid "Spanish"
8762+
msgstr "西班牙語"
8763+
8764+
msgid "Hindi"
8765+
msgstr "印地語"
8766+
8767+
msgid "French"
8768+
msgstr "法語"
8769+
8770+
msgid "German"
8771+
msgstr "德語"
8772+
8773+
msgid "Multiple dialects, supporting 23 dialects"
8774+
msgstr "多種方言,支持 23 種方言"
8775+
8776+
msgid "This interface is used to recognize short audio files within 60 seconds. Supports Mandarin Chinese, English, Cantonese, Japanese, Vietnamese, Malay, Indonesian, Filipino, Thai, Portuguese, Turkish, Arabic, Hindi, French, German, and 23 Chinese dialects."
8777+
msgstr "本介面用於識別 60 秒之內的短音頻文件。支援中文普通話、英語、粵語、日語、越南語、馬來語、印度尼西亞語、菲律賓語、泰語、葡萄牙語、土耳其語、阿拉伯語、印地語、法語、德語及 23 種漢語方言。"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import traceback
2+
3+
from common import forms
4+
from common.exception.app_exception import AppApiException
5+
from common.forms import BaseForm, TooltipLabel
6+
from django.utils.translation import gettext_lazy as _, gettext
7+
8+
from models_provider.base_model_provider import BaseModelCredential, ValidCode
9+
10+
11+
class TencentSSTModelParams(BaseForm):
12+
EngSerViceType = forms.SingleSelect(
13+
TooltipLabel(_('Engine model type'), _('If not passed, the default value is 16k_zh (Chinese universal)')),
14+
required=True,
15+
default_value='16k_zh',
16+
option_list=[
17+
{"value": "8k_zh", "label": _("Chinese telephone universal")},
18+
{"value": "8k_en", "label": _("English telephone universal")},
19+
{"value": "16k_zh", "label": _("Commonly used in Chinese")},
20+
{"value": "16k_zh-PY", "label": _("Chinese, English, and Guangdong")},
21+
{"value": "16k_zh_medical", "label": _("Chinese medical")},
22+
{"value": "16k_en", "label": _("English")},
23+
{"value": "16k_yue", "label": _("Cantonese")},
24+
{"value": "16k_ja", "label": _("Japanese")},
25+
{"value": "16k_ko", "label": _("Korean")},
26+
{"value": "16k_vi", "label": _("Vietnamese")},
27+
{"value": "16k_ms", "label": _("Malay language")},
28+
{"value": "16k_id", "label": _("Indonesian language")},
29+
{"value": "16k_fil", "label": _("Filipino language")},
30+
{"value": "16k_th", "label": _("Thai")},
31+
{"value": "16k_pt", "label": _("Portuguese")},
32+
{"value": "16k_tr", "label": _("Turkish")},
33+
{"value": "16k_ar", "label": _("Arabic")},
34+
{"value": "16k_es", "label": _("Spanish")},
35+
{"value": "16k_hi", "label": _("Hindi")},
36+
{"value": "16k_fr", "label": _("French")},
37+
{"value": "16k_de", "label": _("German")},
38+
{"value": "16k_zh_dialect", "label": _("Multiple dialects, supporting 23 dialects")}
39+
],
40+
value_field='value',
41+
text_field='label'
42+
)
43+
44+
class TencentSTTModelCredential(BaseForm, BaseModelCredential):
45+
REQUIRED_FIELDS = ["SecretId", "SecretKey"]
46+
47+
@classmethod
48+
def _validate_model_type(cls, model_type, provider, raise_exception=False):
49+
if not any(mt['value'] == model_type for mt in provider.get_model_type_list()):
50+
if raise_exception:
51+
raise AppApiException(ValidCode.valid_error.value,
52+
gettext('{model_type} Model type is not supported').format(model_type=model_type))
53+
return False
54+
return True
55+
56+
@classmethod
57+
def _validate_credential_fields(cls, model_credential, raise_exception=False):
58+
missing_keys = [key for key in cls.REQUIRED_FIELDS if key not in model_credential]
59+
if missing_keys:
60+
if raise_exception:
61+
raise AppApiException(ValidCode.valid_error.value,
62+
gettext('{keys} is required').format(keys=", ".join(missing_keys)))
63+
return False
64+
return True
65+
66+
def is_valid(self, model_type, model_name, model_credential, model_params, provider, raise_exception=False):
67+
if not (self._validate_model_type(model_type, provider, raise_exception) and
68+
self._validate_credential_fields(model_credential, raise_exception)):
69+
return False
70+
try:
71+
model = provider.get_model(model_type, model_name, model_credential, **model_params)
72+
model.check_auth()
73+
except Exception as e:
74+
traceback.print_exc()
75+
if raise_exception:
76+
raise AppApiException(ValidCode.valid_error.value,
77+
gettext(
78+
'Verification failed, please check whether the parameters are correct: {error}').format(
79+
error=str(e)))
80+
return False
81+
return True
82+
83+
def encryption_dict(self, model):
84+
return {**model, 'SecretKey': super().encryption(model.get('SecretKey', ''))}
85+
86+
SecretId = forms.PasswordInputField('SecretId', required=True)
87+
SecretKey = forms.PasswordInputField('SecretKey', required=True)
88+
89+
def get_model_params_setting_form(self, model_name):
90+
return TencentSSTModelParams()
Binary file not shown.

0 commit comments

Comments
 (0)