-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Add Anannas AI LLM service integration
#2848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Haleshot
wants to merge
6
commits into
pipecat-ai:main
Choose a base branch
from
Haleshot:haleshot/add-anannas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+250
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d116dc
Add API key
Haleshot 1d94d22
dependency add
Haleshot 56b972c
add `anannas` to README in llm services
Haleshot d37b65e
Anannas LLM service integration
Haleshot 29c39ae
Add anannas service with `DeprecatedModuleProxy`
Haleshot 8caacaf
Add `Anannas LLM Service` implementation
Haleshot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| # AI-COUSTICS | ||
| AICOUSTICS_LICENSE_KEY=... | ||
|
|
||
| # Anannas AI | ||
| ANANNAS_API_KEY=... | ||
|
|
||
| # Anthropic | ||
| ANTHROPIC_API_KEY=... | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # | ||
| # Copyright (c) 2024–2025, Daily | ||
| # | ||
| # SPDX-License-Identifier: BSD 2-Clause License | ||
| # | ||
|
|
||
|
|
||
| import os | ||
|
|
||
| from dotenv import load_dotenv | ||
| from loguru import logger | ||
|
|
||
| from pipecat.adapters.schemas.function_schema import FunctionSchema | ||
| from pipecat.adapters.schemas.tools_schema import ToolsSchema | ||
| from pipecat.audio.turn.smart_turn.base_smart_turn import SmartTurnParams | ||
| from pipecat.audio.turn.smart_turn.local_smart_turn_v3 import LocalSmartTurnAnalyzerV3 | ||
| from pipecat.audio.vad.silero import SileroVADAnalyzer | ||
| from pipecat.audio.vad.vad_analyzer import VADParams | ||
| from pipecat.frames.frames import LLMRunFrame, TTSSpeakFrame | ||
| from pipecat.pipeline.pipeline import Pipeline | ||
| from pipecat.pipeline.runner import PipelineRunner | ||
| from pipecat.pipeline.task import PipelineParams, PipelineTask | ||
| from pipecat.processors.aggregators.llm_context import LLMContext | ||
| from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair | ||
| from pipecat.runner.types import RunnerArguments | ||
| from pipecat.runner.utils import create_transport | ||
| from pipecat.services.anannas.llm import AnannasLLMService | ||
| from pipecat.services.azure.tts import AzureTTSService | ||
| from pipecat.services.deepgram.stt import DeepgramSTTService | ||
| from pipecat.services.llm_service import FunctionCallParams | ||
| from pipecat.transports.base_transport import BaseTransport, TransportParams | ||
| from pipecat.transports.daily.transport import DailyParams | ||
| from pipecat.transports.websocket.fastapi import FastAPIWebsocketParams | ||
|
|
||
| load_dotenv(override=True) | ||
|
|
||
|
|
||
| async def fetch_weather_from_api(params: FunctionCallParams): | ||
| await params.result_callback({"conditions": "nice", "temperature": "75"}) | ||
|
|
||
|
|
||
| # We store functions so objects (e.g. SileroVADAnalyzer) don't get | ||
| # instantiated. The function will be called when the desired transport gets | ||
| # selected. | ||
| transport_params = { | ||
| "daily": lambda: DailyParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(params=VADParams(stop_secs=0.2)), | ||
| turn_analyzer=LocalSmartTurnAnalyzerV3(params=SmartTurnParams()), | ||
| ), | ||
| "twilio": lambda: FastAPIWebsocketParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(params=VADParams(stop_secs=0.2)), | ||
| turn_analyzer=LocalSmartTurnAnalyzerV3(params=SmartTurnParams()), | ||
| ), | ||
| "webrtc": lambda: TransportParams( | ||
| audio_in_enabled=True, | ||
| audio_out_enabled=True, | ||
| vad_analyzer=SileroVADAnalyzer(params=VADParams(stop_secs=0.2)), | ||
| turn_analyzer=LocalSmartTurnAnalyzerV3(params=SmartTurnParams()), | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| async def run_bot(transport: BaseTransport, runner_args: RunnerArguments): | ||
| logger.info(f"Starting bot") | ||
|
|
||
| stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY")) | ||
|
|
||
| tts = AzureTTSService( | ||
| api_key=os.getenv("AZURE_SPEECH_API_KEY"), | ||
| region=os.getenv("AZURE_SPEECH_REGION"), | ||
| voice="en-US-JennyNeural", | ||
| params=AzureTTSService.InputParams(language="en-US", rate="1.1", style="cheerful"), | ||
| ) | ||
|
|
||
| # Anannas AI provides access to 500+ models through a unified gateway | ||
| # You can use any supported model: gpt-4o, claude-3-5-sonnet-20241022, deepseek-chat, etc. | ||
| llm = AnannasLLMService(api_key=os.getenv("ANANNAS_API_KEY"), model="gpt-4o") | ||
| # You can also register a function_name of None to get all functions | ||
| # sent to the same callback with an additional function_name parameter. | ||
| llm.register_function("get_current_weather", fetch_weather_from_api) | ||
|
|
||
| @llm.event_handler("on_function_calls_started") | ||
| async def on_function_calls_started(service, function_calls): | ||
| await tts.queue_frame(TTSSpeakFrame("Let me check on that.")) | ||
|
|
||
| weather_function = FunctionSchema( | ||
| name="get_current_weather", | ||
| description="Get the current weather", | ||
| properties={ | ||
| "location": { | ||
| "type": "string", | ||
| "description": "The city and state, e.g. San Francisco, CA", | ||
| }, | ||
| "format": { | ||
| "type": "string", | ||
| "enum": ["celsius", "fahrenheit"], | ||
| "description": "The temperature unit to use. Infer this from the user's location.", | ||
| }, | ||
| }, | ||
| required=["location", "format"], | ||
| ) | ||
| tools = ToolsSchema(standard_tools=[weather_function]) | ||
| messages = [ | ||
| { | ||
| "role": "system", | ||
| "content": "You are a helpful LLM in a WebRTC call. Your goal is to demonstrate your capabilities in a succinct way. Your output will be converted to audio so don't include special characters in your answers. Respond to what the user said in a creative and helpful way.", | ||
| }, | ||
| ] | ||
|
|
||
| context = LLMContext(messages, tools) | ||
| context_aggregator = LLMContextAggregatorPair(context) | ||
|
|
||
| pipeline = Pipeline( | ||
| [ | ||
| transport.input(), | ||
| stt, | ||
| context_aggregator.user(), | ||
| llm, | ||
| tts, | ||
| transport.output(), | ||
| context_aggregator.assistant(), | ||
| ] | ||
| ) | ||
|
|
||
| task = PipelineTask( | ||
| pipeline, | ||
| params=PipelineParams( | ||
| enable_metrics=True, | ||
| enable_usage_metrics=True, | ||
| ), | ||
| idle_timeout_secs=runner_args.pipeline_idle_timeout_secs, | ||
| ) | ||
|
|
||
| @transport.event_handler("on_client_connected") | ||
| async def on_client_connected(transport, client): | ||
| logger.info(f"Client connected") | ||
| # Kick off the conversation. | ||
| await task.queue_frames([LLMRunFrame()]) | ||
|
|
||
| @transport.event_handler("on_client_disconnected") | ||
| async def on_client_disconnected(transport, client): | ||
| logger.info(f"Client disconnected") | ||
| await task.cancel() | ||
|
|
||
| runner = PipelineRunner(handle_sigint=runner_args.handle_sigint) | ||
|
|
||
| await runner.run(task) | ||
|
|
||
|
|
||
| async def bot(runner_args: RunnerArguments): | ||
| """Main bot entry point compatible with Pipecat Cloud.""" | ||
| transport = await create_transport(runner_args, transport_params) | ||
| await run_bot(transport, runner_args) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| from pipecat.runner.run import main | ||
|
|
||
| main() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # | ||
| # Copyright (c) 2024–2025, Daily | ||
| # | ||
| # SPDX-License-Identifier: BSD 2-Clause License | ||
| # | ||
|
|
||
| import sys | ||
|
|
||
| from pipecat.services import DeprecatedModuleProxy | ||
|
|
||
| from .llm import * | ||
|
|
||
| sys.modules[__name__] = DeprecatedModuleProxy(globals(), "anannas", "anannas.llm") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # | ||
| # Copyright (c) 2024–2025, Daily | ||
| # | ||
| # SPDX-License-Identifier: BSD 2-Clause License | ||
| # | ||
|
|
||
| """Anannas AI LLM service implementation. | ||
| This module provides an OpenAI-compatible interface for interacting with Anannas AI's | ||
| unified model gateway, extending the base OpenAI LLM service functionality. | ||
| """ | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from loguru import logger | ||
|
|
||
| from pipecat.services.openai.llm import OpenAILLMService | ||
|
|
||
|
|
||
| class AnannasLLMService(OpenAILLMService): | ||
| """A service for interacting with Anannas AI's unified model gateway. | ||
| Provides access to 500+ models from OpenAI, Anthropic, Mistral, Gemini, DeepSeek, | ||
| and other providers through a single OpenAI-compatible interface with built-in | ||
| observability and routing capabilities. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| api_key: Optional[str] = None, | ||
| model: str = "gpt-4o", | ||
| base_url: str = "https://api.anannas.ai/v1", | ||
| **kwargs, | ||
| ): | ||
| """Initialize the Anannas AI LLM service. | ||
| Args: | ||
| api_key: The API key for accessing Anannas AI's API. If None, will attempt | ||
| to read from ANANNAS_API_KEY environment variable. | ||
| model: The model identifier to use. Supports any model available through | ||
| Anannas AI (e.g., "gpt-4o", "claude-3-5-sonnet-20241022", | ||
| "deepseek-chat"). Defaults to "gpt-4o". | ||
| base_url: The base URL for Anannas AI API. Defaults to "https://api.anannas.ai/v1". | ||
| **kwargs: Additional keyword arguments passed to OpenAILLMService. | ||
| """ | ||
| super().__init__( | ||
| api_key=api_key, | ||
| base_url=base_url, | ||
| model=model, | ||
| **kwargs, | ||
| ) | ||
|
|
||
| def create_client(self, api_key=None, base_url=None, **kwargs): | ||
| """Create an Anannas AI API client. | ||
| Args: | ||
| api_key: The API key to use for authentication. If None, uses instance default. | ||
| base_url: The base URL for the API. If None, uses instance default. | ||
| **kwargs: Additional arguments passed to the parent client creation method. | ||
| Returns: | ||
| The configured Anannas AI API client instance. | ||
| """ | ||
| logger.debug(f"Creating Anannas AI client with base URL {base_url}") | ||
| return super().create_client(api_key, base_url, **kwargs) | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious re: the naming convention; should this be renamed to
14x-function-calling-anannas?