mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
feat: dotchain lang
This commit is contained in:
29
main.py
29
main.py
@ -1,8 +1,11 @@
|
||||
from typing import Union
|
||||
from typing import Annotated, Union
|
||||
|
||||
from fastapi import FastAPI, Request, status
|
||||
from fastapi import FastAPI, Request, status, Form
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from src.dotchain.runtime.interpreter import program_parser
|
||||
from src.dotchain.runtime.tokenizer import Tokenizer
|
||||
from src.dotchain.runtime.runtime import Runtime
|
||||
from src.blackbox.blackbox_factory import BlackboxFactory
|
||||
import uvicorn
|
||||
|
||||
@ -20,9 +23,27 @@ async def blackbox(blackbox_name: Union[str, None] = None, request: Request = No
|
||||
return await JSONResponse(content={"error": "value error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
return await box.fast_api_handler(request)
|
||||
|
||||
def read_form_image(request: Request):
|
||||
async def inner(field: str):
|
||||
print(field)
|
||||
return "image"
|
||||
return inner
|
||||
|
||||
def read_form_text(request: Request):
|
||||
def inner(field: str):
|
||||
print(field)
|
||||
return "text"
|
||||
return inner
|
||||
|
||||
@app.post("/workflows")
|
||||
async def workflows(reqest: Request):
|
||||
print("workflows")
|
||||
async def workflows(script: Annotated[str, Form()], request: Request=None):
|
||||
dsl_runtime = Runtime(exteral_fun={"print": print,
|
||||
'read_form_image': read_form_image(request),
|
||||
"read_form_text": read_form_text(request)})
|
||||
t = Tokenizer()
|
||||
t.init(script)
|
||||
ast = program_parser(t)
|
||||
ast.exec(dsl_runtime)
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run("main:app", host="127.0.0.1", port=8000, log_level="info")
|
||||
|
||||
Reference in New Issue
Block a user