mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
doc: update swagger
This commit is contained in:
@ -1,11 +1,9 @@
|
|||||||
from .audio_chat import AudioChat
|
from .audio_chat import AudioChat
|
||||||
from .sum import SUM
|
|
||||||
from .sentiment import Sentiment
|
from .sentiment import Sentiment
|
||||||
from .tts import TTS
|
from .tts import TTS
|
||||||
from .asr import ASR
|
from .asr import ASR
|
||||||
from .audio_to_text import AudioToText
|
from .audio_to_text import AudioToText
|
||||||
from .blackbox import Blackbox
|
from .blackbox import Blackbox
|
||||||
from .calculator import Calculator
|
|
||||||
from .text_to_audio import TextToAudio
|
from .text_to_audio import TextToAudio
|
||||||
from .tesou import Tesou
|
from .tesou import Tesou
|
||||||
from .fastchat import Fastchat
|
from .fastchat import Fastchat
|
||||||
@ -18,8 +16,6 @@ class BlackboxFactory:
|
|||||||
self.tts = TTS()
|
self.tts = TTS()
|
||||||
self.asr = ASR(".env.yaml")
|
self.asr = ASR(".env.yaml")
|
||||||
self.sentiment = Sentiment()
|
self.sentiment = Sentiment()
|
||||||
self.sum = SUM()
|
|
||||||
self.calculator = Calculator()
|
|
||||||
self.audio_to_text = AudioToText()
|
self.audio_to_text = AudioToText()
|
||||||
self.text_to_audio = TextToAudio()
|
self.text_to_audio = TextToAudio()
|
||||||
self.tesou = Tesou()
|
self.tesou = Tesou()
|
||||||
@ -36,16 +32,12 @@ class BlackboxFactory:
|
|||||||
return self.audio_to_text
|
return self.audio_to_text
|
||||||
if blackbox_name == "text_to_audio":
|
if blackbox_name == "text_to_audio":
|
||||||
return self.text_to_audio
|
return self.text_to_audio
|
||||||
if blackbox_name == "calculator":
|
|
||||||
return self.calculator
|
|
||||||
if blackbox_name == "asr":
|
if blackbox_name == "asr":
|
||||||
return self.asr
|
return self.asr
|
||||||
if blackbox_name == "tts":
|
if blackbox_name == "tts":
|
||||||
return self.tts
|
return self.tts
|
||||||
if blackbox_name == "sentiment_engine":
|
if blackbox_name == "sentiment_engine":
|
||||||
return self.sentiment
|
return self.sentiment
|
||||||
if blackbox_name == "sum":
|
|
||||||
return self.sum
|
|
||||||
if blackbox_name == "tesou":
|
if blackbox_name == "tesou":
|
||||||
return self.tesou
|
return self.tesou
|
||||||
if blackbox_name == "fastchat":
|
if blackbox_name == "fastchat":
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
from fastapi import status
|
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
from .blackbox import Blackbox
|
|
||||||
|
|
||||||
|
|
||||||
class Calculator(Blackbox):
|
|
||||||
|
|
||||||
"""This class just for example, it show how to implement Blackbox interface."""
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
return self.processing(*args, **kwargs)
|
|
||||||
|
|
||||||
def valid(self, *args, **kwargs) -> bool:
|
|
||||||
data = args[0]
|
|
||||||
return isinstance(data, dict) and "op" in data and "left" in data and "right" in data
|
|
||||||
|
|
||||||
def processing(self, data: dict) -> int | float:
|
|
||||||
if not self.valid(data):
|
|
||||||
raise ValueError("Invalid data")
|
|
||||||
a = data["left"]
|
|
||||||
b = data["right"]
|
|
||||||
op = data["op"]
|
|
||||||
if op == "add":
|
|
||||||
return a + b
|
|
||||||
if op == "sub":
|
|
||||||
return a - b
|
|
||||||
if op == "mul":
|
|
||||||
return a * b
|
|
||||||
if op == "div":
|
|
||||||
return a / b
|
|
||||||
raise ValueError("Invalid operation")
|
|
||||||
|
|
||||||
async def fast_api_handler(self, request) -> any:
|
|
||||||
try:
|
|
||||||
data = await request.json()
|
|
||||||
except:
|
|
||||||
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
|
||||||
try:
|
|
||||||
result = self.processing(data)
|
|
||||||
except ValueError as e:
|
|
||||||
return JSONResponse(content={"error": str(e)}, status_code=status.HTTP_400_BAD_REQUEST)
|
|
||||||
return JSONResponse(content={"result": result}, status_code=status.HTTP_200_OK)
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
from typing import Any, Coroutine
|
|
||||||
|
|
||||||
from fastapi import Request, Response, status
|
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
from .blackbox import Blackbox
|
|
||||||
|
|
||||||
|
|
||||||
class SUM(Blackbox):
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
return self.processing(*args, **kwargs)
|
|
||||||
|
|
||||||
def valid(self, *args, **kwargs) -> bool:
|
|
||||||
data = args[0]
|
|
||||||
return isinstance(data, list)
|
|
||||||
|
|
||||||
def processing(self, *args, **kwargs):
|
|
||||||
return sum(args)
|
|
||||||
|
|
||||||
async def fast_api_handler(self, request: Request) -> Response:
|
|
||||||
try:
|
|
||||||
data = await request.json()
|
|
||||||
except:
|
|
||||||
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
|
||||||
if not self.valid(data):
|
|
||||||
return JSONResponse(content={"error": "format error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
|
||||||
return JSONResponse(content={"result": self.processing(data)}, status_code=status.HTTP_200_OK)
|
|
||||||
21
swagger.yml
21
swagger.yml
@ -54,10 +54,19 @@ components:
|
|||||||
audio:
|
audio:
|
||||||
type: string
|
type: string
|
||||||
format: binary
|
format: binary
|
||||||
|
TextAndImageInput:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
text:
|
||||||
|
type: string
|
||||||
|
image:
|
||||||
|
type: string
|
||||||
|
format: binary
|
||||||
Input:
|
Input:
|
||||||
oneOf:
|
oneOf:
|
||||||
- $ref: "#/components/schemas/TextToAudioInput"
|
- $ref: "#/components/schemas/TextToAudioInput"
|
||||||
- $ref: "#/components/schemas/AudioToTextInput"
|
- $ref: "#/components/schemas/AudioToTextInput"
|
||||||
|
- $ref: "#/components/schemas/TextAndImageInput"
|
||||||
TextResult:
|
TextResult:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -71,5 +80,13 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
description: "Blackbox name"
|
description: "Blackbox name"
|
||||||
enum:
|
enum:
|
||||||
- "text_to_audio"
|
- text_to_audio
|
||||||
- "audio_to_text"
|
- audio_to_text
|
||||||
|
- asr
|
||||||
|
- tts
|
||||||
|
- sentiment_engine
|
||||||
|
- tesou
|
||||||
|
- fastchat
|
||||||
|
- audio_chat
|
||||||
|
- g2e
|
||||||
|
- text_and_image
|
||||||
Reference in New Issue
Block a user