-
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
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ class XInferenceSpeechToText(MaxKBBaseModel, BaseSpeechToText): | |
| api_base: str | ||
| api_key: str | ||
| model: str | ||
| params: dict | ||
|
|
||
| def __init__(self, **kwargs): | ||
| super().__init__(**kwargs) | ||
|
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. No significant issues found in the provided code. However, here are some minor improvements and optimizations you may consider:
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. |
||
|
|
||
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:
should be updated to correctly handle positional and keyword arguments passed to the
get_modelmethod. Here's an improved version:This 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 callingmodel.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.