-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Xinference add #4250
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: Xinference add #4250
Conversation
--bug=1062934 --user=张展玮 【github#4242】添加xinference平台的语音识别模型失败 https://www.tapd.cn/62980211/s/1789683
|
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 |
| model = provider.get_model(model_type, model_name, model_credential, **model_params) | ||
| model.check_auth() | ||
| except Exception as e: | ||
| if isinstance(e, AppApiException): |
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 correct but can be optimized in terms of handling keyword arguments. The line:
try:
model = provider.get_model(model_type, model_name, model_credential)should be updated to correctly handle positional and keyword arguments passed to the get_model method. Here's an improved version:
try:
model = provider.get_model(model_type, model_name, **model_credential, **model_params)
except Exception as e:
if isinstance(e, AppApiException):
# Handle specific exceptions here
passThis change uses the unpacking operator (**) effectively to expand dictionaries into the function call, accommodating both positional and key-value pairs that might be used when calling model.cred. This approach ensures compatibility with different sets of input parameters without having to manually check which arguments are present.
Also, consider adding logging around exception captures to provide more context on what went wrong during the execution process.
| params: dict | ||
|
|
||
| def __init__(self, **kwargs): | ||
| super().__init__(**kwargs) |
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.
No significant issues found in the provided code. However, here are some minor improvements and optimizations you may consider:
-
Docstring: Adding a docstring to describe the parameters would be helpful.
-
Validation: Ensure
api_keyis correctly validated or secured (e.g., not exposed). -
Parameter Initialization: Optionally, initialize default values or enforce non-empty strings for any required fields beyond
model.
Here's an improved version with these considerations:
from transformers import MaxKBBaseModel, BaseSpeechToText
class XInferenceSpeechToText(MaxKBBaseModel, BaseSpeechToText):
"""
A speech-to-text model using X inference API.
Parameters:
api_base (str): The base URL of the X inference API.
api_key (str): Your personal access token for authentication.
model (str): Name of the speech-to-text model to use by X inference.
params (dict): Additional parameters specific to the X inference API call.
Defaults to an empty dictionary if not specified.
Attributes:
api_base (str): The base URL of the X inference API set during initialization.
api_key (str): Your personal access token for authentication.
model (str): Name of the speech-to-text model used by X inference.
params (dict): Additional parameters passed to the X inference service.
"""
api_base: str
api_key: str
model: str = ""
params: dict = {}
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Validate input parameters here based on their type and constraints
if not isinstance(api_base, str) or not api_base.strip():
raise ValueError("Invalid api_base. It must be a non-empty string.")
if not isinstance(api_key, str):
raise ValueError("Invalid api_key. It must be a string.")
if not isinstance(model, str) or not model.strip():
logging.warning(f"Warning: Invalid model name '{model}'. Using '' as default.")
self.model = ""
if "params" in kwargs:
if not isinstance(kwargs["params"], dict):
raise ValueError("Invalid 'params'. Must be a dictionary.")
self.params.update(kwargs.get("params", {}))These modifications enhance clarity and robustness in handling inputs, ensuring that all necessary parameters are properly initialized and validated.
fix: Xinference add --bug=1062934 --user=张展玮 【github#4242】添加xinference平台的语音识别模型失败 https://www.tapd.cn/62980211/s/1789683