feat: calculator;

This commit is contained in:
Dan Chen
2024-03-19 09:07:57 +08:00
parent f773627aa4
commit 4e2a4ef63c
3 changed files with 4 additions and 4 deletions

View File

@ -7,7 +7,6 @@ from blackbox.text_to_audio import TextToAudio
class BlackboxFactory: class BlackboxFactory:
def create_blackbox(self, blackbox_type: str, blackbox_config: dict) -> Blackbox: def create_blackbox(self, blackbox_type: str, blackbox_config: dict) -> Blackbox:
if blackbox_type == "audio_to_text": if blackbox_type == "audio_to_text":
return AudioToText(blackbox_config) return AudioToText(blackbox_config)
if blackbox_type == "text_to_audio": if blackbox_type == "text_to_audio":

View File

@ -4,12 +4,12 @@ from blackbox.blackbox import Blackbox
class Calculator(Blackbox): class Calculator(Blackbox):
"""This class just for example, it show how to implement Blackbox interface."""
"""This class just for example, it show how to implement Blackbox interface."""
def valid(self, data: any) -> bool: def valid(self, data: any) -> bool:
return isinstance(data, dict) and "op" in data and "left" in data and "right" in data return isinstance(data, dict) and "op" in data and "left" in data and "right" in data
def processing(self, data: dict) -> any: def processing(self, data: dict) -> any:
if not self.valid(data): if not self.valid(data):
raise ValueError("Invalid data") raise ValueError("Invalid data")

View File

@ -5,6 +5,7 @@ from gtts import gTTS
from io import BytesIO from io import BytesIO
class TextToAudio(Blackbox): class TextToAudio(Blackbox):
def valid(self, data: any) -> bool: def valid(self, data: any) -> bool:
return isinstance(data, str) return isinstance(data, str)