package seems to work

This commit is contained in:
Moishe Lettvin
2023-12-27 12:17:00 -05:00
parent 2d24309a94
commit 9e9007f7b7
29 changed files with 42 additions and 75 deletions

View File

@@ -0,0 +1,56 @@
import logging
from abc import abstractmethod
from dataclasses import dataclass
from typing import Generator
from PIL import Image
class AIService:
def __init__(self):
self.logger = logging.getLogger("bot-instance")
def close(self):
pass
class LLMService(AIService):
# Generate a set of responses to a prompt. Yields a list of responses.
@abstractmethod
def run_llm_async(
self, messages
) -> Generator[str, None, None]:
pass
# Generate a responses to a prompt. Returns the response
@abstractmethod
def run_llm(
self, messages
) -> str or None:
pass
class TTSService(AIService):
# Some TTS services require a specific sample rate. We default to 16k
def get_mic_sample_rate(self):
return 16000
# Converts the sentence to audio. Yields a list of audio frames that can
# be sent to the microphone device
@abstractmethod
def run_tts(self, sentence) -> Generator[bytes, None, None]:
pass
class ImageGenService(AIService):
# Renders the image. Returns an Image object.
@abstractmethod
def run_image_gen(self, sentence) -> Image.Image:
pass
@dataclass
class AIServiceConfig:
tts: TTSService
image: ImageGenService
llm: LLMService