Merge pull request #62 from daily-co/anthropic-support
Anthropic LLM service
This commit is contained in:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "dailyai"
|
name = "dailyai"
|
||||||
version = "0.0.3"
|
version = "0.0.3.1"
|
||||||
description = "An open source framework for real-time, multi-modal, conversational AI applications"
|
description = "An open source framework for real-time, multi-modal, conversational AI applications"
|
||||||
license = { text = "BSD 2-Clause License" }
|
license = { text = "BSD 2-Clause License" }
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@@ -21,6 +21,7 @@ classifiers = [
|
|||||||
]
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aiohttp",
|
"aiohttp",
|
||||||
|
"anthropic",
|
||||||
"azure-cognitiveservices-speech",
|
"azure-cognitiveservices-speech",
|
||||||
"daily-python",
|
"daily-python",
|
||||||
"fal",
|
"fal",
|
||||||
|
|||||||
35
src/dailyai/services/anthropic_llm_service.py
Normal file
35
src/dailyai/services/anthropic_llm_service.py
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user