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

@@ -1,9 +1,16 @@
from typing import AsyncGenerator
from anthropic import AsyncAnthropic
from dailyai.pipeline.frames import Frame, LLMMessagesFrame, TextFrame
from dailyai.services.ai_services import LLMService
try:
from anthropic import AsyncAnthropic
except ModuleNotFoundError as e:
print(f"Exception: {e}")
print(
"In order to use Anthropic, you need to `pip install dailyai[anthropic]`. Also, set `ANTHROPIC_API_KEY` environment variable.")
raise Exception(f"Missing module: {e}")
class AnthropicLLMService(LLMService):