Skip to content
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

services(azure): fix AzureLLMService #174

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to **pipecat** will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- GoogleLLMService `api_key` argument is now mandatory.

### Fixed

- Fixed AzureLLMService.

## [0.0.23] - 2024-05-23

### Fixed
Expand Down
10 changes: 3 additions & 7 deletions examples/foundational/12a-describe-video-gemini-flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,15 @@ async def main(room_url: str, token):
)
)

tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
)

user_response = UserResponseAggregator()

image_requester = UserImageRequester()

vision_aggregator = VisionImageFrameAggregator()

google = GoogleLLMService(model="gemini-1.5-flash-latest")
google = GoogleLLMService(
model="gemini-1.5-flash-latest",
api_key=os.getenv("GOOGLE_API_KEY"))

tts = ElevenLabsTTSService(
aiohttp_session=session,
Expand Down
6 changes: 0 additions & 6 deletions examples/foundational/12b-describe-video-gpt-4o.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ async def main(room_url: str, token):
)
)

tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
)

user_response = UserResponseAggregator()

image_requester = UserImageRequester()
Expand Down
6 changes: 0 additions & 6 deletions examples/foundational/12c-describe-video-anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ async def main(room_url: str, token):
)
)

tts = ElevenLabsTTSService(
aiohttp_session=session,
api_key=os.getenv("ELEVENLABS_API_KEY"),
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
)

user_response = UserResponseAggregator()

image_requester = UserImageRequester()
Expand Down
6 changes: 3 additions & 3 deletions src/pipecat/services/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class AnthropicLLMService(LLMService):

def __init__(
self,
api_key,
model="claude-3-opus-20240229",
max_tokens=1024):
api_key: str,
model: str = "claude-3-opus-20240229",
max_tokens: int = 1024):
super().__init__()
self._client = AsyncAnthropic(api_key=api_key)
self._model = model
Expand Down
26 changes: 14 additions & 12 deletions src/pipecat/services/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from PIL import Image
from typing import AsyncGenerator

from numpy import str_
from openai import AsyncAzureOpenAI

from pipecat.frames.frames import AudioRawFrame, ErrorFrame, Frame, URLImageRawFrame
Expand Down Expand Up @@ -73,17 +74,18 @@ class AzureLLMService(BaseOpenAILLMService):
def __init__(
self,
*,
api_key,
endpoint,
api_version="2023-12-01-preview",
model):
super().__init__(api_key=api_key, model=model)
api_key: str,
endpoint: str,
model: str,
api_version: str = "2023-12-01-preview"):
# Initialize variables before calling parent __init__() because that
# will call create_client() and we need those values there.
self._endpoint = endpoint
self._api_version = api_version
self._model: str = model
super().__init__(api_key=api_key, model=model)

def create_client(self, api_key=None, base_url=None):
self._client = AsyncAzureOpenAI(
return AsyncAzureOpenAI(
api_key=api_key,
azure_endpoint=self._endpoint,
api_version=self._api_version,
Expand All @@ -95,12 +97,12 @@ class AzureImageGenServiceREST(ImageGenService):
def __init__(
self,
*,
api_version="2023-06-01-preview",
image_size: str,
aiohttp_session: aiohttp.ClientSession,
api_key,
endpoint,
model,
image_size: str,
api_key: str,
endpoint: str,
model: str,
api_version="2023-06-01-preview",
):
super().__init__()

Expand Down
4 changes: 2 additions & 2 deletions src/pipecat/services/fireworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

class FireworksLLMService(BaseOpenAILLMService):
def __init__(self,
model="accounts/fireworks/models/firefunction-v1",
base_url="https://api.fireworks.ai/inference/v1"):
model: str = "accounts/fireworks/models/firefunction-v1",
base_url: str = "https://api.fireworks.ai/inference/v1"):
super().__init__(model, base_url)
10 changes: 3 additions & 7 deletions src/pipecat/services/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@ class GoogleLLMService(LLMService):
franca for all LLM services, so that it is easy to switch between different LLMs.
"""

def __init__(self, model="gemini-1.5-flash-latest", api_key=None, **kwargs):
def __init__(self, api_key: str, model: str = "gemini-1.5-flash-latest", **kwargs):
super().__init__(**kwargs)
self.model = model
gai.configure(api_key=api_key or os.environ["GOOGLE_API_KEY"])
self.create_client()

def create_client(self):
self._client = gai.GenerativeModel(self.model)
gai.configure(api_key=api_key)
self._client = gai.GenerativeModel(model)

def _get_messages_from_openai_context(
self, context: OpenAILLMContext) -> List[glm.Content]:
Expand Down
2 changes: 1 addition & 1 deletion src/pipecat/services/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

class OLLamaLLMService(BaseOpenAILLMService):

def __init__(self, model="llama2", base_url="http://localhost:11434/v1"):
def __init__(self, model: str = "llama2", base_url: str = "http://localhost:11434/v1"):
super().__init__(model=model, base_url=base_url, api_key="ollama")
4 changes: 2 additions & 2 deletions src/pipecat/services/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class BaseOpenAILLMService(LLMService):
def __init__(self, model: str, api_key=None, base_url=None):
super().__init__()
self._model: str = model
self.create_client(api_key=api_key, base_url=base_url)
self._client = self.create_client(api_key=api_key, base_url=base_url)

def create_client(self, api_key=None, base_url=None):
self._client = AsyncOpenAI(api_key=api_key, base_url=base_url)
return AsyncOpenAI(api_key=api_key, base_url=base_url)

async def _stream_chat_completions(
self, context: OpenAILLMContext
Expand Down
Loading