KIMB-technologies cc4bb9a7e8
All checks were successful
Build and push Docker image at git tag / build (push) Successful in 55s
Fix #1
2024-10-31 16:25:37 +01:00

65 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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, BackgroundTasks
from fastapi.staticfiles import StaticFiles
from fastapi.responses import JSONResponse
from ums.agent.process import MessageProcessor
from ums.utils import AgentMessage, AgentResponse, const
class WebMain():
def __init__(self):
self.msg_process = MessageProcessor()
self._init_app()
self._add_routes()
def _init_app(self):
self.app = FastAPI(
title="Agenten Plattform",
description="Agenten Plattform Agent",
openapi_url="/api/schema.json",
docs_url='/api',
redoc_url=None
)
self.app.mount(
"/static",
StaticFiles(directory=os.path.join(const.PUBLIC_PATH, 'static')),
name="static"
)
self.app.mount(
"/docs",
StaticFiles(directory=os.path.join(const.PUBLIC_PATH, 'docs'), html=True),
name="docs"
)
def _add_routes(self):
@self.app.get("/", response_class=JSONResponse, summary="Link list")
def index():
return {
"title" : "Agenten Plattform Agent",
"./message" : "Messaged from the Management",
"./api" : "API Overview",
"./docs" : "Documentation"
}
@self.app.post("/message", summary="Send a message to this agent")
def message(request: Request, message:AgentMessage, background_tasks: BackgroundTasks) -> AgentResponse:
return self.msg_process.new_message(message, background_tasks)
if __name__ == "ums.agent.main" and os.environ.get('SERVE', 'false').lower() == 'true':
main = WebMain()
app = main.app