Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from models_provider.base_model_provider import BaseModelCredential, ValidCode
from django.utils.translation import gettext as _

# class AliyunBaiLianOmiSTTModelParams(BaseForm):
# CueWord = forms.TextInputField(
# TooltipLabel(_('CueWord'), _('If not passed, the default value is What is this audio saying? Only answer the audio content')),
# required=True,
# default_value='这段音频在说什么,只回答音频的内容',
# )
class AliyunBaiLianOmiSTTModelParams(BaseForm):
CueWord = forms.TextInputField(
TooltipLabel(_('CueWord'), _('If not passed, the default value is What is this audio saying? Only answer the audio content')),
required=True,
default_value='这段音频在说什么,只回答音频的内容',
)


class AliyunBaiLianOmiSTTModelCredential(BaseForm, BaseModelCredential):
Expand Down Expand Up @@ -70,4 +70,4 @@ def encryption_dict(self, model: Dict[str, object]) -> Dict[str, object]:

def get_model_params_setting_form(self, model_name):

pass
return AliyunBaiLianOmiSTTModelParams()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code appears to be valid Python and doesn't contain any significant irregularities, issues, or optimizations. The AliyunBaiLianOmiSTTModelParams class and its methods seem to be correctly defined according to Django Form API. The changes made in the last three lines should also work without issue.

However, there is a minor inconsistency in the line endings. It seems like you want to replace \No newline at end of file, which isn't used properly for multiline comments starting with @@. Instead, you might have intended to remove that comment entirely if it was no longer needed.

Here's a slightly more formatted version of the cleaned-up code:

# from models_provider.base_model_provider import BaseModelCredential, ValidCode
from django.utils.translation import gettext_lazy as _

class AliyunBaiLianOmiSTTModelParams(forms.Form):
    CueWord = forms.CharField(
        label=_('CueWord'),
        help_text=_('If not passed, the default value is "What is this audio saying? Only answer the audio content".'),
        required=True,
        initial='这段音频在说什么,只回答音频的内容',
    )

class AliyunBaiLianOmiSTTModelCredential(BaseForm, BaseModelCredential):
    # Method implementation here

    def encryption_dict(self, model: dict) -> dict:
        # Encryption logic here

    def get_model_params_setting_form(self, model_name):
        return AliyunBaiLianOmiSTTModelParams()

Note that I replaced forms.TextInputField with forms.CharField, which is generally recommended for text fields due to better handling and compatibility across different browsers and platforms. This change aligns with modern best practices in form field definitions.

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def speech_to_text(self, audio_file):
"format": "mp3",
},
},
{"type": "text", "text": '这段音频在说什么,只回答音频的内容'},
{"type": "text", "text": self.params.get('CueWord')},
],
},
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like there is an indentation issue at the beginning of one line. Here’s the corrected version:

@@ -68,7 +68,7 @@
         return {
             "request": [
                 {
                     "audio_data": {
                         "uri": f"s3://{bucket_name}/{key}",
                         "format": "mp3"
                     },
-                    {"type": "text", "text": '这段音频在说什么,只回答音频的内容'}
+                    {"type": "text", "text": self.params.get('CueWord')}
                 }
             ]
         }

Improvements/Notes:

  1. Indentation: Ensured all lines within the return dictionary are properly indented to match the previous block.
  2. Consistency: Kept the parameter extraction using self.params.get('CueWord') consistent with other uses in the function.

This correction ensures that the JSON structure remains valid and adheres to Python syntax conventions.

Expand Down
66 changes: 33 additions & 33 deletions apps/models_provider/impl/tencent_model_provider/credential/stt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,38 @@
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 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"]
Expand Down Expand Up @@ -87,4 +87,4 @@ def encryption_dict(self, model):
SecretKey = forms.PasswordInputField('SecretKey', required=True)

def get_model_params_setting_form(self, model_name):
pass
return TencentSSTModelParams()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code does not contain any immediate issues that would prevent it from running correctly. However, I can suggest a few optimizations:

  1. Import Statements: Ensure there are no unnecessary imports at the top of the file.

  2. Docstring Consistency: Check if all functions and classes have consistent docstrings, which could improve readability.

  3. Unused Function get_model_params_setting_form: The function get_model_params_setting_form is currently empty and might be redundant if its purpose has already been served elsewhere in the codebase.

Here's an optimized version of the code with some minor adjustments:

from models_provider.base_model_provider import BaseModelCredential, ValidCode

class TencentSSTModelParams(BaseForm):
    """Class for configuring engine model type."""
    
    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):
    """
    Class for storing credentials for speech-to-text services.
    
    Attributes:
        REQUIRED_FIELDS: Required fields for authentication.
    """
    REQUIRE_FIELDS = ["SecretId", "SecretKey"]
    
    def encryption_dict(self, model):
        return {}
        
    SecretKey = forms.PasswordInputField('secretkey', required=True)
    
    def get_model_params_setting_form(self):
        # Return instance of TencentSSTModelParams class
        return TencentSSTModelParams()

By applying these changes, you should make the code more readable and maintainable without adding significant overhead.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def speech_to_text(self, audio_file):
# 实例化一个请求对象,每个接口都会对应一个request对象
req = models.SentenceRecognitionRequest()
params = {
"EngSerViceType": '16k_zh',
"EngSerViceType": self.params.get('EngSerViceType'),
"SourceType": 1,
"VoiceFormat": "mp3",
"Data": _v.decode(),
Expand Down
Loading