Begin Interface

This commit is contained in:
Magnus Bender 2024-10-08 13:08:17 +02:00
parent cff39d61de
commit 28eee676c4
Signed by: bender
GPG Key ID: 5149A211831F2BD7
5 changed files with 105 additions and 44 deletions

View File

@ -11,7 +11,7 @@
# https://www.gnu.org/licenses/gpl-3.0.txt # https://www.gnu.org/licenses/gpl-3.0.txt
pdoc ./ums/ \ pdoc ./ums/ \
--output-directory ./docs/ \ --output-directory ./web/public/docs/ \
--no-browser \ --no-browser \
--docformat google \ --docformat google \
--template-directory ./utils/doc-template --template-directory ./utils/doc-template

View File

@ -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 {}

View File

@ -8,27 +8,50 @@
# source code released under the terms of GNU Public License Version 3 # source code released under the terms of GNU Public License Version 3
# https://www.gnu.org/licenses/gpl-3.0.txt # https://www.gnu.org/licenses/gpl-3.0.txt
# TEST ONLY from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
from ums.management.interface import Interface
from typing import Union
from fastapi import FastAPI
from ums.utils import AgentMessage, RiddleData, RiddleDataType, RiddleSolution
from ums.management.db import DB 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 __init__(self):
def read_root(): self._init_app()
return {"Hello": "World"} self._init_templates()
@app.get("/test") self.db = DB()
def huhu():
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
)
def _init_templates(self):
self.template = Jinja2Templates(
directory=TEMPLATE_PATH,
auto_reload=True
)
def _add_routers(self):
interface_router = Interface(self.template, self.db)
self.app.include_router(interface_router.router)
def _add_routes(self):
@self.app.get("/test", summary="Test")
def huhu(request: Request) -> AgentMessage:
ex = AgentMessage( ex = AgentMessage(
id="ex1", id="ex1",
riddle={ riddle={
@ -49,15 +72,11 @@ def huhu():
explanation="Written in line 6 after 'Name:'" explanation="Written in line 6 after 'Name:'"
) )
#ins_count = db.add_message('from', 'to', ex) ins_count = self.db.add_message('from', 'to', ex)
db.set_processed(34234) self.db.set_processed(ins_count)
print(db.by_count(3))
return ex return ex
if __name__ == "ums.management.main":
@app.get("/items/{item_id}") main = WebMain()
def read_item(item_id: int, q: Union[str, None] = None): app = main.app
return {"item_id": item_id, "q": q}

View File

@ -18,3 +18,4 @@ import os
BASE_PATH = '/ums-agenten' BASE_PATH = '/ums-agenten'
SHARE_PATH = os.path.join(BASE_PATH, 'share') SHARE_PATH = os.path.join(BASE_PATH, 'share')
PERSIST_PATH = os.path.join(BASE_PATH, 'persist') PERSIST_PATH = os.path.join(BASE_PATH, 'persist')
TEMPLATE_PATH = os.path.join(BASE_PATH, 'plattform', 'web', 'templates')

View File

@ -1,8 +1,14 @@
<html> <html>
<head> <head>
<title>UMS-Agenten Management</title> <title>UMS-Agenten &ndash; Management</title>
</head> </head>
<body> <body>
<h1>Empty</h1> <h1>UMS-Agenten &ndash; Management</h1>
<ul>
<li><a href="/app/" target="_blank">Web App (small GUI)</a></li>
<li><a href="/app/new" target="_blank">Add Riddle via GUI</a></li>
<li><a href="/api/" target="_blank">API Documentations</a></li>
<li><a href="/docs/" target="_blank">Code Documentation</a></li>
</ul>
</body> </body>
</html> </html>