use conditional imports and show help errors if modules not found

This commit is contained in:
Aleix Conchillo Flaqué
2024-04-03 15:09:12 -07:00
parent 23735cb3a3
commit 3528f5d735
19 changed files with 137 additions and 67 deletions

View File

@@ -9,12 +9,18 @@ from dailyai.services.ai_services import TTSService, ImageGenService
from PIL import Image
# See .env.example for Azure configuration needed
from azure.cognitiveservices.speech import (
SpeechSynthesizer,
SpeechConfig,
ResultReason,
CancellationReason,
)
try:
from azure.cognitiveservices.speech import (
SpeechSynthesizer,
SpeechConfig,
ResultReason,
CancellationReason,
)
except ModuleNotFoundError as e:
print(f"Exception: {e}")
print(
"In order to use Azure TTS, you need to `pip install dailyai[azure]`. Also, set `SPEECH_KEY` and `SPEECH_REGION` environment variables.")
raise Exception(f"Missing module: {e}")
from dailyai.services.openai_api_llm_service import BaseOpenAILLMService