Basic web loop works

This commit is contained in:
Niels Geens
2024-11-07 15:10:17 +01:00
parent 6e78a0f0bd
commit 970414e56d
9 changed files with 218 additions and 132 deletions

View File

@@ -34,8 +34,10 @@ class TestLLM:
yield "</reasoning>"
class Main:
def __init__(self):
self._config = Config()
@classmethod
async def create(cls, config: Config):
self = cls()
self._config = config
self._system_prompt = self._config.system_prompt.read_text()
self._action_schema = self._config.action_schema.read_text()
@@ -62,13 +64,14 @@ class Main:
validator=XMLValidator(self._action_schema),
parser=ResponseParser(self._io_buffer)
)
self._ws_manager = WebSocketManager(
self._ws_manager = await WebSocketManager.create(
self._agent,
self._io_buffer
)
self._app = web.Application()
self._init_routes()
return self
@property
def app(self):
@@ -114,6 +117,8 @@ class Main:
return response
if __name__ == "__main__":
main = Main()
print("Web server started at http://localhost:8080")
web.run_app(main.app, port=8080)
loop = asyncio.new_event_loop()
config = Config()
main = loop.run_until_complete(Main.create(config))
print(f"Web server started at http://{config.host}:{config.port}")
web.run_app(main.app, loop=loop, host=config.host, port=config.port)