Skip to content
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

Improve Fish Audio API error handling #18

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/fishaudio/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ meta:
entrypoint: main
language: python
version: '3.12'
version: 0.0.1
version: 0.0.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta.version should keep in 0.0.1

name: fishaudio_tool
plugins:
tools:
Expand All @@ -27,4 +27,4 @@ resource:
tags:
- utilities
type: plugin
version: 0.0.1
version: 0.0.2
22 changes: 12 additions & 10 deletions tools/fishaudio/tools/fishaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ def tts(self, content, voice, latency, audio_format) -> Generator[bytes, None, N
reference_id=voice,
latency=latency,
)
with httpx.stream(
"POST",
self.url_base + "/v1/tts",
content=ormsgpack.packb(request, option=ormsgpack.OPT_SERIALIZE_PYDANTIC),
headers=self.headers(),
timeout=None,
) as response:
if response.status_code != 200:
raise InvokeBadRequestError(f"Error: {response.status_code} - {response.text}")
yield from response.iter_bytes()
try:
with httpx.stream(
"POST",
self.url_base + "/v1/tts",
content=ormsgpack.packb(request, option=ormsgpack.OPT_SERIALIZE_PYDANTIC),
headers=self.headers(),
timeout=None,
) as response:
response.raise_for_status()
yield from response.iter_bytes()
except httpx.HTTPStatusError as e:
raise InvokeBadRequestError(f"{e.response.status_code} - {str(e)}")

def model_list(self, page_number):
params = {
Expand Down
4 changes: 2 additions & 2 deletions tools/fishaudio/tools/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessag
try:
data = self._tts(content, voice_id, audio_format)
yield self.create_blob_message(blob=data, meta={"mime_type": f"audio/{audio_format}"})
except Exception:
yield self.create_text_message("Text to speech service error, please check the network")
except Exception as e:
yield self.create_text_message(f"Text to speech service error, please check the network; error: {e}")

def _tts(self, content: str, voice_id: str, audio_format: str) -> bytes:
api_key = self.runtime.credentials.get("api_key")
Expand Down
Loading