From 28eee676c48ec2488d3a4a3b8be91190678aab96 Mon Sep 17 00:00:00 2001 From: KIMB-technologies Date: Tue, 8 Oct 2024 13:08:17 +0200 Subject: [PATCH] Begin Interface --- docs.sh | 2 +- ums/management/interface.py | 35 +++++++++++++ ums/management/main.py | 99 ++++++++++++++++++++++--------------- ums/utils/const.py | 3 +- web/public/index.html | 10 +++- 5 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 ums/management/interface.py diff --git a/docs.sh b/docs.sh index 98600d3..856aa01 100755 --- a/docs.sh +++ b/docs.sh @@ -11,7 +11,7 @@ # https://www.gnu.org/licenses/gpl-3.0.txt pdoc ./ums/ \ - --output-directory ./docs/ \ + --output-directory ./web/public/docs/ \ --no-browser \ --docformat google \ --template-directory ./utils/doc-template \ No newline at end of file diff --git a/ums/management/interface.py b/ums/management/interface.py new file mode 100644 index 0000000..5fcfaa9 --- /dev/null +++ b/ums/management/interface.py @@ -0,0 +1,35 @@ +# Agenten Plattform +# +# (c) 2024 Magnus Bender +# Institute of Humanities-Centered Artificial Intelligence (CHAI) +# Universitaet Hamburg +# https://www.chai.uni-hamburg.de/~bender +# +# source code released under the terms of GNU Public License Version 3 +# https://www.gnu.org/licenses/gpl-3.0.txt + +from fastapi import APIRouter, Request +from fastapi.templating import Jinja2Templates + +from ums.management.db import DB + +class Interface(): + + def __init__(self, template:Jinja2Templates, db:DB): + self.template = template + self.db = db + + self.router = APIRouter( + prefix="/app", + tags=["app, gui"] + ) + + self._add_routes() + + def _add_routes(self): + @self.router.get("/", summary="Test") + def corpus(request: Request): + + print(self.db.by_count(3)) + + return {} \ No newline at end of file diff --git a/ums/management/main.py b/ums/management/main.py index df6c083..d729999 100644 --- a/ums/management/main.py +++ b/ums/management/main.py @@ -8,56 +8,75 @@ # source code released under the terms of GNU Public License Version 3 # https://www.gnu.org/licenses/gpl-3.0.txt -# TEST ONLY +from fastapi import FastAPI, Request +from fastapi.templating import Jinja2Templates - - -from typing import Union - -from fastapi import FastAPI - -from ums.utils import AgentMessage, RiddleData, RiddleDataType, RiddleSolution +from ums.management.interface import Interface from ums.management.db import DB -db = DB() +from ums.utils import AgentMessage, RiddleData, RiddleDataType, RiddleSolution, TEMPLATE_PATH -app = FastAPI() +class WebMain(): -@app.get("/") -def read_root(): - return {"Hello": "World"} + def __init__(self): + self._init_app() + self._init_templates() -@app.get("/test") -def huhu(): - ex = AgentMessage( - id="ex1", - riddle={ - "context":"Example 1", - "question":"Get the name of the person." - }, - data=[ - RiddleData( - type=RiddleDataType.TEXT, - file_plain="./cv.txt" - ) - ] + self.db = DB() + + self._add_routes() + self._add_routers() + + + def _init_app(self): + self.app = FastAPI( + title="Agenten Plattform", + description="Agenten Plattform – Management", + openapi_url="/api/schema.json", + docs_url='/api', + redoc_url=None ) - ex.status.extract.required = False - ex.solution = RiddleSolution( - solution="Otto", - explanation="Written in line 6 after 'Name:'" - ) + def _init_templates(self): + self.template = Jinja2Templates( + directory=TEMPLATE_PATH, + auto_reload=True + ) - #ins_count = db.add_message('from', 'to', ex) - db.set_processed(34234) + def _add_routers(self): + interface_router = Interface(self.template, self.db) + self.app.include_router(interface_router.router) - print(db.by_count(3)) - - return ex + def _add_routes(self): + + @self.app.get("/test", summary="Test") + def huhu(request: Request) -> AgentMessage: + ex = AgentMessage( + id="ex1", + riddle={ + "context":"Example 1", + "question":"Get the name of the person." + }, + data=[ + RiddleData( + type=RiddleDataType.TEXT, + file_plain="./cv.txt" + ) + ] + ) + ex.status.extract.required = False + ex.solution = RiddleSolution( + solution="Otto", + explanation="Written in line 6 after 'Name:'" + ) -@app.get("/items/{item_id}") -def read_item(item_id: int, q: Union[str, None] = None): - return {"item_id": item_id, "q": q} \ No newline at end of file + ins_count = self.db.add_message('from', 'to', ex) + self.db.set_processed(ins_count) + + return ex + +if __name__ == "ums.management.main": + main = WebMain() + app = main.app \ No newline at end of file diff --git a/ums/utils/const.py b/ums/utils/const.py index fc2931f..78e53c7 100644 --- a/ums/utils/const.py +++ b/ums/utils/const.py @@ -17,4 +17,5 @@ import os BASE_PATH = '/ums-agenten' SHARE_PATH = os.path.join(BASE_PATH, 'share') -PERSIST_PATH = os.path.join(BASE_PATH, 'persist') \ No newline at end of file +PERSIST_PATH = os.path.join(BASE_PATH, 'persist') +TEMPLATE_PATH = os.path.join(BASE_PATH, 'plattform', 'web', 'templates') \ No newline at end of file diff --git a/web/public/index.html b/web/public/index.html index bdd923b..586e2d9 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -1,8 +1,14 @@ - UMS-Agenten Management + UMS-Agenten – Management -

Empty

+

UMS-Agenten – Management

+ \ No newline at end of file