Skip to content

Commit cb34991

Browse files
authored
fix: add type hints for App model and improve error handling in audio services (#12677)
Signed-off-by: -LAN- <[email protected]>
1 parent c700364 commit cb34991

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

api/controllers/console/app/audio.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError
2323
from core.model_runtime.errors.invoke import InvokeError
2424
from libs.login import login_required
25-
from models.model import AppMode
25+
from models import App, AppMode
2626
from services.audio_service import AudioService
2727
from services.errors.audio import (
2828
AudioTooLargeServiceError,
@@ -79,7 +79,7 @@ class ChatMessageTextApi(Resource):
7979
@login_required
8080
@account_initialization_required
8181
@get_app_model
82-
def post(self, app_model):
82+
def post(self, app_model: App):
8383
from werkzeug.exceptions import InternalServerError
8484

8585
try:
@@ -98,9 +98,13 @@ def post(self, app_model):
9898
and app_model.workflow.features_dict
9999
):
100100
text_to_speech = app_model.workflow.features_dict.get("text_to_speech")
101+
if text_to_speech is None:
102+
raise ValueError("TTS is not enabled")
101103
voice = args.get("voice") or text_to_speech.get("voice")
102104
else:
103105
try:
106+
if app_model.app_model_config is None:
107+
raise ValueError("AppModelConfig not found")
104108
voice = args.get("voice") or app_model.app_model_config.text_to_speech_dict.get("voice")
105109
except Exception:
106110
voice = None

api/services/audio_service.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def transcript_tts(
8282
from app import app
8383
from extensions.ext_database import db
8484

85-
def invoke_tts(text_content: str, app_model, voice: Optional[str] = None):
85+
def invoke_tts(text_content: str, app_model: App, voice: Optional[str] = None):
8686
with app.app_context():
8787
if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:
8888
workflow = app_model.workflow
@@ -95,6 +95,8 @@ def invoke_tts(text_content: str, app_model, voice: Optional[str] = None):
9595

9696
voice = features_dict["text_to_speech"].get("voice") if voice is None else voice
9797
else:
98+
if app_model.app_model_config is None:
99+
raise ValueError("AppModelConfig not found")
98100
text_to_speech_dict = app_model.app_model_config.text_to_speech_dict
99101

100102
if not text_to_speech_dict.get("enabled"):

0 commit comments

Comments
 (0)