All checks were successful
Build and push Docker image at git tag / build (push) Successful in 7m7s
84 lines
1.9 KiB
Python
84 lines
1.9 KiB
Python
# 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
|
||
|
||
import os
|
||
|
||
from fastapi import FastAPI, Request
|
||
from fastapi.templating import Jinja2Templates
|
||
|
||
from ums.management.interface import Interface
|
||
from ums.management.db import DB
|
||
|
||
from ums.utils import AgentMessage, RiddleData, RiddleDataType, RiddleSolution, TEMPLATE_PATH
|
||
|
||
class WebMain():
|
||
|
||
def __init__(self):
|
||
self._init_app()
|
||
self._init_templates()
|
||
|
||
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
|
||
)
|
||
|
||
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(
|
||
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:'"
|
||
)
|
||
|
||
ins_count = self.db.add_message('from', 'to', ex)
|
||
self.db.set_processed(ins_count)
|
||
|
||
return ex
|
||
|
||
if __name__ == "ums.management.main" and os.environ.get('SERVE', 'false') == 'true':
|
||
main = WebMain()
|
||
app = main.app |