-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Models rerank stt #3934
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
fix: Models rerank stt #3934
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,10 +61,11 @@ def speech_to_text(self, audio_file): | |
| messages=messages, | ||
| result_format="message", | ||
| ) | ||
|
|
||
| text = response["output"]["choices"][0]["message"].content[0]["text"] | ||
|
|
||
| return text | ||
| if response.status_code == 200: | ||
| text = response["output"]["choices"][0]["message"].content[0]["text"] | ||
| return text | ||
| else: | ||
| raise Exception('Error: ', response.message) | ||
|
|
||
| except Exception as err: | ||
| maxkb_logger.error(f":Error: {str(err)}: {traceback.format_exc()}") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code seems to be for converting speech from an audio file to text using a translation API. The function Irregularities:
def speech_to_text(self, audio_file):
try:
# Assuming 'chatGPT' is initialized elsewhere (client setup for API calls)
response = chatGPT.complete(
model_id=model,
prompt=prompt,
messages=messages,
result_format="message"
)
if response.status_code == 200:
text = response["output"]["choices"][0].get("message", {}).get("content", []).get(0).get("text")
return text
elif response.status_code >= 400:
raise Exception(f"HTTP request failed with status {response.status_code}: '{response.json().get('detail', {})['message']}'")
else:
raise Exception("Unexpected response received")
except Exception as err:
maxkb_logger.error(f"Error during speech-to-text conversion process: {err}", exc_info=True)
return NoneOptimization Suggestions:
By addressing these points, the code improves robustness and usability, making it easier to integrate into larger applications. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"] | ||
|
|
@@ -87,4 +87,4 @@ def encryption_dict(self, model): | |
| SecretKey = forms.PasswordInputField('SecretKey', required=True) | ||
|
|
||
| def get_model_params_setting_form(self, model_name): | ||
| return TencentSSTModelParams() | ||
| pass | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet appears to be incomplete, with only the opening line of To optimize the code, consider adding docstrings to each class method if they don't already exist. Additionally, ensure that all imported modules are properly defined at the beginning of the file. Here's a corrected version: 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"]
def SecretId(self):
"""
Returns the secret ID field.
:return: The SecretId form field instance.
"""
return forms.CharField('SecretId', required=True)
def SecretKey(self):
"""
Returns the secret key field.
:return: The SecretKey form field instance.
"""
return forms.PasswordInputField('SecretKey', required=True)
def get_model_params_setting_form(self, model_name):
"""
Retrieves the model parameters setting form based on the given model name.
:param model_name: Name of the model.
:type model_name: str
:return: An instance of TencentSSTModelParams.
:rtype: TencentSSTModelParams
"""
# Implement logic to get model-specific params form
return TencentSSTModelParams()This should improve readability and maintainability. |
||
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 code looks mostly correct, but there are a few issues to consider:
Indentation: The code has inconsistent indentation between lines 3 and 22. It would be good practice to use consistent spacing to avoid confusion.
Duplicate Code: There is repetition in the
AliyunBaiLianOmiStTModelParamsclass definition starting from line 7 to line 28. While this might not affect functionality, it can clutter the code and make maintenance more difficult. Consider using inheritance or composition if these fields are common across different classes.Comments Formatting: The comments around parameters seem to have mixed formats (
#) which could lead to inconsistencies. Consistently using#throughout the file might improve readability.End of Line Characters: The trailing newline character at the end of the file is unnecessary. This can cause unexpected behavior when working with source control systems that manage files based on differences.
Here's an improved version of the code with some adjustments:
Key Changes:
AliyunBaiLianOmiSTTModelParamsclass.#.These changes should help improve the overall structure and clarity of the code while maintaining its functionality.