-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tts and speech2text model for gpustack
- Loading branch information
1 parent
2dbc5ff
commit 9d1b7cf
Showing
8 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Optional | ||
|
||
from dify_plugin import OAICompatSpeechToTextModel | ||
from dify_plugin.entities.model.speech2text import SpeechToTextResult | ||
|
||
|
||
class GPUStackSpeechToTextModel(OAICompatSpeechToTextModel): | ||
""" | ||
Model class for GPUStack Speech to text model. | ||
""" | ||
|
||
def _invoke( | ||
self, | ||
model: str, | ||
credentials: dict, | ||
audio: bytes, | ||
user: Optional[str] = None, | ||
) -> SpeechToTextResult: | ||
compatible_credentials = self._get_compatible_credentials(credentials) | ||
return super()._invoke(model, compatible_credentials, audio, user) | ||
|
||
def validate_credentials(self, model: str, credentials: dict) -> None: | ||
""" | ||
Validate model credentials | ||
:param model: model name | ||
:param credentials: model credentials | ||
""" | ||
compatible_credentials = self._get_compatible_credentials(credentials) | ||
super().validate_credentials(model, compatible_credentials) | ||
|
||
def _get_compatible_credentials(self, credentials: dict) -> dict: | ||
credentials = credentials.copy() | ||
base_url = credentials["endpoint_url"].rstrip("/").removesuffix("/v1-openai") | ||
credentials["endpoint_url"] = f"{base_url}/v1-openai" | ||
return credentials | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from collections.abc import Generator | ||
from dify_plugin import OAICompatTextToSpeechModel | ||
from dify_plugin.entities.model.tts import TTSResult | ||
|
||
|
||
class GPUStackTextToSpeechModel(OAICompatTextToSpeechModel): | ||
""" | ||
Model class for GPUStack Text to Speech model. | ||
""" | ||
|
||
def _invoke( | ||
self, | ||
model: str, | ||
credentials: dict, | ||
text: str, | ||
user: str | None = None, | ||
) -> TTSResult | Generator: | ||
compatible_credentials = self._get_compatible_credentials(credentials) | ||
return super()._invoke(model, compatible_credentials, text, user) | ||
|
||
def validate_credentials(self, model: str, credentials: dict, user: Optional[str] = None) -> None: | ||
""" | ||
Validate model credentials | ||
:param model: model name | ||
:param credentials: model credentials | ||
:param user: unique user id | ||
""" | ||
compatible_credentials = self._get_compatible_credentials(credentials) | ||
super().validate_credentials(model, compatible_credentials) | ||
|
||
def _get_compatible_credentials(self, credentials: dict) -> dict: | ||
""" | ||
Get compatible credentials | ||
:param credentials: model credentials | ||
:return: compatible credentials | ||
""" | ||
compatible_credentials = credentials.copy() | ||
base_url = credentials["endpoint_url"].rstrip("/").removesuffix("/v1-openai") | ||
compatible_credentials["endpoint_url"] = f"{base_url}/v1-openai" | ||
|
||
return compatible_credentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters