refactor: Support different types of aliyun stt model#4448
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
The provided code has several issues:
-
The file appears to be incomplete; there should be closing braces (
}) after most but not all classes and functions. -
Some lines with
@@ -0,0 +1,68are placeholder additions for the changes being checked. Ensure that these comments reflect actual added content, especially within classes and methods likespeech_to_text,check_auth, etc. -
Method definitions in Python require a colon at the end of the header (e.g.,
def check_auth():). You have one colon where it's missing (@staticmethod def is_cache_model()). -
The imports and class definition are quite extensive without actually implementing any functionality. Consider removing unused import statements and reducing line length.
-
There are repeated instances of importing
MaxKBBaseModelalthough they seem superfluous since the same model base implementation already inherits this class.
Here’s an optimized version while addressing some of those points:
# coding=utf-8
"""
@project: MaxKB
@Author:niu
@file:default_stt.py
@date:2025/12/5 15:40
@desc:
"""
import os
from typing import Dict
from models_provider.base_model_provider import MaxKBBaseModel
from models_provider.impl.base_stt import BaseSpeechToText
class AliyunBaiLianDefaultSpeechToText(MaxKBBaseModel, BaseSpeechToText):
def check_auth(self):
# Implement authentication logic here
pass
def speech_to_text(self, audio_file):
raise NotImplementedError("This method should be implemented.")
@staticmethod
def is_cache_model() -> bool:
"""Check if the model supports caching."""
return False
@staticmethod
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs) -> 'AliyunBaiLianDefaultSpeechToText':
from models_provider.impl.aliyun_bai_lian_model_provider.model.stt import (
AliyunBaiLianOmiSpeechToText,
AliyunBaiLianSpeechToText,
AliyunBaiLianAsrSpeechToText,
)
stt_type = model_credential.get('type')
if stt_type == 'qwen':
return AliyunBaiLianAsrSpeechToText(
model=model_name,
api_key=model_credential['api_key'],
api_url=model_credential['api_url'],
params=model_kwargs,
**model_kwargs,
)
elif stt_type == 'omni':
return AliyunBaiLianOmiSpeechToText(
model=model_name,
api_key=model_credential['api_key'],
api_url=model_credential['api_url'],
params=model_kwargs,
**model_kwargs,
)
else:
return AliyunBaiLianSpeechToText(
model=model_name,
api_key=model_credential['api_key'],
params=model_kwargs,
**model_kwargs,
)
# Missing closing brace for AliyunBaiLianDefaultSpeechToText closureEnsure that the remaining lines include proper closures (}), particularly after defining the final classes (if any). If additional files or modules are referenced elsewhere, make sure they exist and can be imported correctly.
| AliyunBaiLianDefaultSpeechToText)) | ||
| .append_default_model_info(model_info_list[3]) | ||
| .append_default_model_info(model_info_list[4]) | ||
| .append_default_model_info(model_info_list[0]) |
There was a problem hiding this comment.
The provided code contains several improvements and corrections:
-
Imports:
- Corrected
AliyunBaiLianDefaultSTTModelCredentialto match its implementation (note that it seems there was a typo). - Added missing import statement for
AliyunBaiLianOriTTIConfig.
- Corrected
-
Initialization of Models:
- Fixed the constructor call by using correct attribute names (
module_type,credential, etc.).
- Fixed the constructor call by using correct attribute names (
-
Appending Default Model Info:
- Added an extra default model info with ID 'default' and associated credential and model instance.
-
Module Name Correction:
- Changed
QwenOriTTIConfigtoQwenTTIConfig.
- Changed
Here's the updated code snippet:
from common.config.default_config import QwenTTIConfig, ALIYUN_BAI_LIAN_TTI_MODEL_ID_DEFAULT
...
aliyun_bai_lian_tti_model_configuration = AliyunBaiLianTTIConfiguration(
module_name=ALIYUN_BAI_LIAN_TTI_MODULE_NAME,
alias=_('tti'),
version='1.0'
)
module_info_tti_list = [
AliyunBaiLianTTIModuleInfo(aliyun_bai_lian_tti_model_configuration.module_id),
]This should resolve the issues and improve the structure of the model initialization process.
refactor: Support different types of aliyun stt model