Added hf_llm_engine and config

This commit is contained in:
Niels Geens
2024-11-04 17:08:52 +01:00
parent 5da6dca5ec
commit 70ed16f8ab
12 changed files with 330 additions and 93 deletions

View File

@@ -5,16 +5,20 @@ import asyncio
import mimetypes
import time
from .config import Config
from .hf_llm_engine import HfLlmEngine
from .llm_engine import LlmEngine
from .local_llm_engine import LocalLlmEngine
from .response_parser import ResponseParser
from .system_metrics import SystemMetrics
from .web_agent import WebAgent
from .web_agent import WebAgent
from .web_io_buffer import WebIOBuffer
from .web_io_buffer import WebIOBuffer
from .web_socket_manager import WebSocketManager
from .working_memory import WorkingMemory
from .xml_validator import XMLValidator
from .response_parser import ResponseParser
from .web_agent import WebAgent
from .web_io_buffer import WebIOBuffer
mimetypes.add_type("application/javascript", ".js")
mimetypes.add_type("application/javascript", ".jsx")
@@ -31,13 +35,23 @@ class TestLLM:
class Main:
def __init__(self):
self._base_dir = Path(__file__).parent.parent
self._system_prompt = (self._base_dir / "system_prompt.md").read_text()
self._action_schema = (self._base_dir / "action_schema.xsd").read_text()
self._static_dir = self._base_dir / "static"
self._config = Config()
self._llm = LlmEngine("/root/model")
#self._llm = TestLLM()
self._system_prompt = self._config.system_prompt.read_text()
self._action_schema = self._config.action_schema.read_text()
match self._config.llm_engine:
case "local":
self._llm = LocalLlmEngine(self._config.model)
case "hf":
self._llm = HfLlmEngine(
model_id=self._config.model,
api_token=self._config.hf_api_token
)
case "test":
self._llm = TestLLM()
case _:
raise ValueError(f"Invalid LLM engine: {self._config.llm_engine}")
self._io_buffer = WebIOBuffer()
self._agent = WebAgent(
system_prompt=self._system_prompt,
@@ -64,13 +78,13 @@ class Main:
self._app.middlewares.append(self._cors_middleware)
self._app.router.add_get("/ws", self._ws_manager.handle_websocket)
self._app.router.add_get("/", self._serve_index)
self._app.router.add_static("/static/", self._static_dir, show_index=False)
self._app.router.add_static("/assets/", self._static_dir / "assets", show_index=False)
self._app.router.add_static("/static/", self._config.static_files, show_index=False)
self._app.router.add_static("/assets/", self._config.static_files / "assets", show_index=False)
self._app.router.add_get("/{path:.*}", self._serve_index)
async def _serve_index(self, request: web.Request) -> web.Response:
"""Serve the React application HTML for any unmatched routes."""
index_path = self._static_dir / "index.html"
index_path = self._config.static_files / "index.html"
if not index_path.exists():
raise web.HTTPNotFound()