Begin Interface
This commit is contained in:
parent
cff39d61de
commit
28eee676c4
2
docs.sh
2
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
|
35
ums/management/interface.py
Normal file
35
ums/management/interface.py
Normal 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 {}
|
@ -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}
|
||||
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
|
@ -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')
|
||||
PERSIST_PATH = os.path.join(BASE_PATH, 'persist')
|
||||
TEMPLATE_PATH = os.path.join(BASE_PATH, 'plattform', 'web', 'templates')
|
@ -1,8 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>UMS-Agenten Management</title>
|
||||
<title>UMS-Agenten – Management</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Empty</h1>
|
||||
<h1>UMS-Agenten – 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>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user