mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
3
main.py
3
main.py
@ -1,8 +1,7 @@
|
||||
import uvicorn
|
||||
import logging
|
||||
from injector import Injector,inject
|
||||
from src.log.handler import LogHandler
|
||||
from src.configuration import EnvConf, LogConf, singleton
|
||||
from src.configuration import LogConf, singleton
|
||||
|
||||
@singleton
|
||||
class Main():
|
||||
|
||||
0
src/blackbox/__init__.py
Normal file
0
src/blackbox/__init__.py
Normal file
@ -1,6 +1,4 @@
|
||||
|
||||
from .audio_to_text import AudioToText
|
||||
from .text_to_audio import TextToAudio
|
||||
from .sum import Sum
|
||||
from fastapi import Request, Response
|
||||
from .blackbox import Blackbox
|
||||
@ -10,6 +8,8 @@ from ..dotchain.runtime.runtime import Runtime
|
||||
from ..dotchain.runtime.tokenizer import Tokenizer
|
||||
from ..dotchain.runtime.ast import Literal
|
||||
import json
|
||||
import re
|
||||
|
||||
|
||||
def read_binay(io):
|
||||
return Literal(io.read())
|
||||
@ -17,31 +17,31 @@ def read_binay(io):
|
||||
def new_map():
|
||||
return Literal({})
|
||||
|
||||
def set_map(map: dict, key, value):
|
||||
def set_map_value(map: dict, key, value):
|
||||
map[key] = value
|
||||
return map
|
||||
|
||||
def jsonfiy(obj):
|
||||
return Literal(json.dumps(obj))
|
||||
|
||||
def get_value(d: dict, key):
|
||||
def get_map_value(d: dict, key):
|
||||
value = d.get(key)
|
||||
if value is dict:
|
||||
return value
|
||||
if value is list:
|
||||
return value
|
||||
return Literal(value)
|
||||
def get_map_int(d: dict, key):
|
||||
value = d.get(key)
|
||||
return Literal(int(value))
|
||||
|
||||
@singleton
|
||||
class Workflow(Blackbox):
|
||||
|
||||
@inject
|
||||
def __init__(self, sum: Sum,
|
||||
audio_to_text: AudioToText,
|
||||
text_to_audio: TextToAudio) -> None:
|
||||
def __init__(self, sum: Sum) -> None:
|
||||
self.sum_blackbox = sum
|
||||
self.audio_to_text = audio_to_text
|
||||
self.text_to_audio_blackbox = text_to_audio
|
||||
self.cost = 0
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.processing(*args, **kwargs)
|
||||
@ -52,8 +52,19 @@ class Workflow(Blackbox):
|
||||
def sum(self, *args, **kwargs):
|
||||
return Literal(self.sum_blackbox.processing(*args, **kwargs))
|
||||
|
||||
def get_cost(self):
|
||||
return self.cost
|
||||
|
||||
def blackbox_example(self):
|
||||
self.cost_increase(10);
|
||||
return Literal("Blackbox result")
|
||||
|
||||
def cost_increase(self, cost):
|
||||
self.cost+=cost
|
||||
return self.cost
|
||||
|
||||
async def processing(self, *args, **kwargs):
|
||||
request = args[0]
|
||||
request: Request = args[0]
|
||||
json = await request.json()
|
||||
content = None
|
||||
mdeia_type = None
|
||||
@ -67,25 +78,25 @@ class Workflow(Blackbox):
|
||||
def add_header(key, value):
|
||||
nonlocal headers
|
||||
headers[key] = value
|
||||
|
||||
script = json["script"]
|
||||
script = request.query_params["script"]
|
||||
t = Tokenizer()
|
||||
t.init(script)
|
||||
runtime = Runtime(
|
||||
context={"json": json},
|
||||
exteral_fun={
|
||||
"new_map": new_map,
|
||||
"set_map": set_map,
|
||||
"audio_to_text": self.audio_to_text,
|
||||
"text_to_audio": self.text_to_audio,
|
||||
"get_value": get_value,
|
||||
"print": print,
|
||||
"new_map": new_map,
|
||||
"set_map_value": set_map_value,
|
||||
"get_map_value": get_map_value,
|
||||
"set_content": set_content,
|
||||
"set_media_type": set_media_type,
|
||||
"add_header": add_header,
|
||||
"sum": self.sum,
|
||||
"read_binay": read_binay,
|
||||
"jsonfiy": jsonfiy,
|
||||
"get_map_int": get_map_int,
|
||||
"blackbox_example": self.blackbox_example,
|
||||
"get_cost": self.get_cost,
|
||||
}
|
||||
)
|
||||
ast = program_parser(t)
|
||||
@ -97,7 +108,6 @@ class Workflow(Blackbox):
|
||||
|
||||
async def fast_api_handler(self, request: Request):
|
||||
return await self.processing(request)
|
||||
# return Response(content=b.read(), media_type="audio/mp3", headers={"Content-Disposition": "attachment; filename=audio.mp3"})
|
||||
|
||||
"""
|
||||
let b = new_map();
|
||||
|
||||
Reference in New Issue
Block a user