diff --git a/pyproject.toml b/pyproject.toml index 00958d83c..d2e61fdbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "dailyai" -version = "0.0.3" +version = "0.0.3.1" description = "An open source framework for real-time, multi-modal, conversational AI applications" license = { text = "BSD 2-Clause License" } readme = "README.md" @@ -21,6 +21,7 @@ classifiers = [ ] dependencies = [ "aiohttp", + "anthropic", "azure-cognitiveservices-speech", "daily-python", "fal", diff --git a/src/dailyai/services/anthropic_llm_service.py b/src/dailyai/services/anthropic_llm_service.py new file mode 100644 index 000000000..a58c610d7 --- /dev/null +++ b/src/dailyai/services/anthropic_llm_service.py @@ -0,0 +1,35 @@ +import asyncio +import os +from typing import AsyncGenerator +from anthropic import AsyncAnthropic +from dailyai.pipeline.frames import Frame, LLMMessagesQueueFrame, TextFrame + +from dailyai.services.ai_services import LLMService + + +class AnthropicLLMService(LLMService): + + def __init__(self, api_key, model="claude-3-opus-20240229", max_tokens=1024): + super().__init__() + self.client = AsyncAnthropic(api_key=api_key) + self.model = model + self.max_tokens = max_tokens + + async def process_frame(self, frame: Frame) -> AsyncGenerator[Frame, None]: + if not isinstance(frame, LLMMessagesQueueFrame): + yield frame + + stream = await self.client.messages.create( + max_tokens=self.max_tokens, + messages=[ + { + "role": "user", + "content": "Hello, Claude", + } + ], + model=self.model, + stream=True, + ) + async for event in stream: + if event.type == "content_block_delta": + yield TextFrame(event.delta.text)