66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
import asyncio
|
|
from pathlib import Path
|
|
|
|
from .llm_engine import LlmEngine
|
|
from .system_metrics import SystemMetrics
|
|
from .web_agent import WebAgent
|
|
from .web_io_buffer import WebIOBuffer
|
|
from .web_server import WebServer
|
|
from .working_memory import WorkingMemory
|
|
from .xml_validator import XMLValidator
|
|
from .response_parser import ResponseParser
|
|
|
|
async def run_web_server():
|
|
"""Run the web server with default configuration."""
|
|
base_dir = Path(__file__).parent.parent
|
|
|
|
# Load system prompt and action schema
|
|
system_prompt = (base_dir / "system_prompt.md").read_text()
|
|
action_schema = (base_dir / "action_schema.xsd").read_text()
|
|
|
|
# Initialize core components
|
|
llm = LlmEngine("/root/model")
|
|
io_buffer = WebIOBuffer()
|
|
agent = WebAgent(
|
|
system_prompt=system_prompt,
|
|
action_schema=action_schema,
|
|
working_memory=WorkingMemory(),
|
|
system_metrics=SystemMetrics(),
|
|
llm=llm,
|
|
validator=XMLValidator(action_schema),
|
|
parser=ResponseParser(io_buffer)
|
|
)
|
|
|
|
# Start the web server
|
|
server = WebServer(agent, io_buffer, "0.0.0.0", 8080)
|
|
await server.start()
|
|
|
|
try:
|
|
while True:
|
|
if server._response_tasks:
|
|
done, _ = await asyncio.wait(
|
|
server._response_tasks,
|
|
timeout=0.1,
|
|
return_when=asyncio.FIRST_COMPLETED
|
|
)
|
|
for task in done:
|
|
try:
|
|
await task
|
|
except asyncio.CancelledError:
|
|
print("Task was cancelled")
|
|
except Exception as e:
|
|
print(f"Task error: {e}")
|
|
server._response_tasks.discard(task) # Use discard to prevent KeyError
|
|
await asyncio.sleep(0.1)
|
|
except KeyboardInterrupt:
|
|
print("\nShutting down...")
|
|
finally:
|
|
await server.stop()
|
|
|
|
def main():
|
|
"""Main entry point for the SIA application."""
|
|
asyncio.run(run_web_server())
|
|
|
|
if __name__ == "__main__":
|
|
main()
|