gemma demo working but this is an old main

This commit is contained in:
Ubuntu
2024-07-05 00:50:24 +00:00
parent e4967107b2
commit 61a0799faa
2 changed files with 13 additions and 14 deletions

View File

@@ -142,9 +142,9 @@ class TTSService(AIService):
elif isinstance(frame, StartInterruptionFrame): elif isinstance(frame, StartInterruptionFrame):
self._current_sentence = "" self._current_sentence = ""
await self.push_frame(frame, direction) await self.push_frame(frame, direction)
elif isinstance(frame, LLMFullResponseEndFrame) or isinstance(frame, EndFrame): elif isinstance(frame, EndFrame):
self._current_sentence = "" if self._current_sentence:
await self._push_tts_frames(self._current_sentence) await self._push_tts_frames(self._current_sentence)
await self.push_frame(frame) await self.push_frame(frame)
elif isinstance(frame, LLMFullResponseEndFrame): elif isinstance(frame, LLMFullResponseEndFrame):
if self._current_sentence: if self._current_sentence:

View File

@@ -9,7 +9,7 @@ import base64
import io import io
import json import json
from typing import Any, AsyncGenerator, List, Literal from typing import AsyncGenerator, List, Literal
from loguru import logger from loguru import logger
from PIL import Image from PIL import Image
@@ -53,7 +53,7 @@ except ModuleNotFoundError as e:
raise Exception(f"Missing module: {e}") raise Exception(f"Missing module: {e}")
class OpenAIUnhandledFunctionException(BaseException): class OpenAIUnhandledFunctionException(Exception):
pass pass
@@ -67,7 +67,7 @@ class BaseOpenAILLMService(LLMService):
calls from the LLM. calls from the LLM.
""" """
def __init__(self, model: str, api_key=None, base_url=None, **kwargs): def __init__(self, *, model: str, api_key=None, base_url=None, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self._model: str = model self._model: str = model
self._client = self.create_client(api_key=api_key, base_url=base_url, **kwargs) self._client = self.create_client(api_key=api_key, base_url=base_url, **kwargs)
@@ -109,10 +109,7 @@ class BaseOpenAILLMService(LLMService):
del message["data"] del message["data"]
del message["mime_type"] del message["mime_type"]
try: chunks = await self.get_chat_completions(context, messages)
chunks = await self.get_chat_completions(context, messages)
except Exception as e:
logger.error(f"{self} exception: {e}")
return chunks return chunks
@@ -214,7 +211,7 @@ class BaseOpenAILLMService(LLMService):
elif isinstance(result, type(None)): elif isinstance(result, type(None)):
pass pass
else: else:
raise BaseException(f"Unknown return type from function callback: {type(result)}") raise TypeError(f"Unknown return type from function callback: {type(result)}")
async def process_frame(self, frame: Frame, direction: FrameDirection): async def process_frame(self, frame: Frame, direction: FrameDirection):
await super().process_frame(frame, direction) await super().process_frame(frame, direction)
@@ -231,14 +228,16 @@ class BaseOpenAILLMService(LLMService):
if context: if context:
await self.push_frame(LLMFullResponseStartFrame()) await self.push_frame(LLMFullResponseStartFrame())
await self.start_processing_metrics()
await self._process_context(context) await self._process_context(context)
await self.stop_processing_metrics()
await self.push_frame(LLMFullResponseEndFrame()) await self.push_frame(LLMFullResponseEndFrame())
class OpenAILLMService(BaseOpenAILLMService): class OpenAILLMService(BaseOpenAILLMService):
def __init__(self, model="gpt-4o", **kwargs): def __init__(self, *, model: str = "gpt-4o", **kwargs):
super().__init__(model, **kwargs) super().__init__(model=model, **kwargs)
class OpenAIImageGenService(ImageGenService): class OpenAIImageGenService(ImageGenService):
@@ -334,4 +333,4 @@ class OpenAITTSService(TTSService):
frame = AudioRawFrame(chunk, 24_000, 1) frame = AudioRawFrame(chunk, 24_000, 1)
yield frame yield frame
except BadRequestError as e: except BadRequestError as e:
logger.error(f"{self} error generating TTS: {e}") logger.exception(f"{self} error generating TTS: {e}")