Updated main file
This commit is contained in:
@@ -1,17 +1,59 @@
|
||||
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."""
|
||||
# Load system prompt and action schema
|
||||
base_dir = Path(__file__).parent.parent
|
||||
with open(base_dir / "system_prompt.txt", "r") as f:
|
||||
system_prompt = f.read()
|
||||
with open(base_dir / "action_schema.xsd", "r") as f:
|
||||
action_schema = f.read()
|
||||
|
||||
# Initialize core components
|
||||
llm = LlmEngine("/root/model")
|
||||
working_memory = WorkingMemory()
|
||||
system_metrics = SystemMetrics()
|
||||
validator = XMLValidator(action_schema)
|
||||
io_buffer = WebIOBuffer()
|
||||
parser = ResponseParser(io_buffer)
|
||||
|
||||
# Create web agent
|
||||
agent = WebAgent(
|
||||
system_prompt=system_prompt,
|
||||
action_schema=action_schema,
|
||||
working_memory=working_memory,
|
||||
system_metrics=system_metrics,
|
||||
llm=llm,
|
||||
validator=validator,
|
||||
parser=parser
|
||||
)
|
||||
|
||||
# Create and start web server
|
||||
server = WebServer(agent, io_buffer)
|
||||
await server.start()
|
||||
|
||||
try:
|
||||
# Keep running until interrupted
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nShutting down...")
|
||||
finally:
|
||||
await server.stop()
|
||||
|
||||
def main():
|
||||
"""Main entry point for the SIA application."""
|
||||
system_prompt_path = "system_prompt.txt"
|
||||
action_schema_path = "action_schema.xsd"
|
||||
model_path = "/root/model"
|
||||
|
||||
with open(system_prompt_path, 'r') as f:
|
||||
system_prompt = f.read()
|
||||
with open(action_schema_path, 'r') as f:
|
||||
action_schema = f.read()
|
||||
|
||||
print("todo")
|
||||
asyncio.run(run_web_server())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -18,10 +18,17 @@ from sia.parse_error_entry import ParseErrorEntry
|
||||
from sia.delete_command import DeleteCommand
|
||||
from sia.entry import Entry
|
||||
|
||||
class TestBaseAgent(BaseAgent):
|
||||
"""Concrete implementation of BaseAgent for testing."""
|
||||
def run(self) -> None:
|
||||
pass
|
||||
class TestLogHandler(logging.Handler):
|
||||
"""Custom logging handler that stores records for test verification."""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.records = []
|
||||
|
||||
def emit(self, record):
|
||||
self.records.append(record)
|
||||
|
||||
def clear(self):
|
||||
self.records = []
|
||||
|
||||
class MockEntry(Entry):
|
||||
"""Mock entry class that properly extends Entry."""
|
||||
@@ -40,6 +47,11 @@ class MockEntry(Entry):
|
||||
elem.text = "<![CDATA[mock content]]>"
|
||||
return elem
|
||||
|
||||
class TestBaseAgent(BaseAgent):
|
||||
"""Concrete implementation of BaseAgent for testing."""
|
||||
def run(self) -> None:
|
||||
pass
|
||||
|
||||
class BaseAgentTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Set up test cases with mocked components."""
|
||||
@@ -82,10 +94,10 @@ class BaseAgentTest(unittest.TestCase):
|
||||
# Set timestamp for entries
|
||||
self.test_timestamp = datetime(2024, 10, 31, 12, 0, 0)
|
||||
|
||||
# Capture logging output
|
||||
self.log_records = []
|
||||
logging.getLogger().handlers = []
|
||||
logging.getLogger().addHandler(self.log_handler)
|
||||
# Setup logging
|
||||
self.log_handler = TestLogHandler()
|
||||
logger = logging.getLogger()
|
||||
logger.addHandler(self.log_handler)
|
||||
|
||||
def log_handler(self, record):
|
||||
"""Capture log records for testing."""
|
||||
@@ -93,6 +105,10 @@ class BaseAgentTest(unittest.TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
"""Clean up resources."""
|
||||
# Remove log handler
|
||||
logger = logging.getLogger()
|
||||
logger.removeHandler(self.log_handler)
|
||||
|
||||
if hasattr(self, 'agent'):
|
||||
del self.agent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user