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,56 +8,75 @@
# 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():
ex = AgentMessage( self._add_routes()
id="ex1", self._add_routers()
riddle={
"context":"Example 1",
"question":"Get the name of the person." def _init_app(self):
}, self.app = FastAPI(
data=[ title="Agenten Plattform",
RiddleData( description="Agenten Plattform Management",
type=RiddleDataType.TEXT, openapi_url="/api/schema.json",
file_plain="./cv.txt" docs_url='/api',
) redoc_url=None
]
) )
ex.status.extract.required = False
ex.solution = RiddleSolution( def _init_templates(self):
solution="Otto", self.template = Jinja2Templates(
explanation="Written in line 6 after 'Name:'" directory=TEMPLATE_PATH,
) auto_reload=True
)
#ins_count = db.add_message('from', 'to', ex) def _add_routers(self):
db.set_processed(34234) interface_router = Interface(self.template, self.db)
self.app.include_router(interface_router.router)
print(db.by_count(3)) def _add_routes(self):
return ex @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}") ins_count = self.db.add_message('from', 'to', ex)
def read_item(item_id: int, q: Union[str, None] = None): self.db.set_processed(ins_count)
return {"item_id": item_id, "q": q}
return ex
if __name__ == "ums.management.main":
main = WebMain()
app = main.app

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>