Added template support.
Some checks failed
Build Base Application / Build (push) Failing after 2m0s

This commit is contained in:
retoor 2024-12-28 16:21:33 +01:00
parent 559b4ede76
commit 026d72f29f
2 changed files with 9 additions and 0 deletions

View File

@ -15,6 +15,7 @@ package_dir =
python_requires = >=3.7
install_requires =
aiohttp
aiohttp-jinja2
dataset
ipython
openai

View File

@ -4,6 +4,9 @@ import json
import time
import uuid
import aiohttp_jinja2
import jinja2
import dataset
from aiohttp import web
@ -29,6 +32,7 @@ class BaseApplication(RPCApplication):
basic_password=None,
cookie_name=None,
session=None,
template_path=None,
*args,
**kwargs,
):
@ -40,6 +44,7 @@ class BaseApplication(RPCApplication):
middlewares.append(self.request_middleware)
middlewares.append(self.base64_auth_middleware)
middlewares.append(self.session_middleware)
self.template_path = template_path and template_path or pathlib.Path(__file__).parent / "templates"
self.agents = {}
super().__init__(middlewares=middlewares, *args, **kwargs)
@ -98,6 +103,9 @@ class BaseApplication(RPCApplication):
return await handler(request)
async def render_template(self, name, request, context):
return aiohttp_jinja2.render_template(name, request=self.request, context)
@web.middleware
async def request_middleware(self, request: web.Request, handler):
time_start = time.time()