Added docker support
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
from typing import Annotated, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validator
|
||||
|
||||
from agent import Agent, AgentMessage
|
||||
from paths import debug_path, prompt_path
|
||||
from utils import Event, Timeline
|
||||
from windowizer import Window, Windowizer
|
||||
|
||||
@@ -146,8 +146,10 @@ class StructureBuilder:
|
||||
"""
|
||||
self._agent = agent
|
||||
self._windowizer = windowizer
|
||||
with open("prompts/structure_builder.md", "r", encoding="utf-8") as f:
|
||||
self._system_prompt = AgentMessage(content=f.read(), role="system")
|
||||
self._system_prompt = AgentMessage(
|
||||
content=prompt_path("structure_builder.md").read_text(encoding="utf-8"),
|
||||
role="system",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _validate_result(result: _BuildResult, window: Window[Event]) -> None:
|
||||
@@ -192,25 +194,20 @@ class StructureBuilder:
|
||||
),
|
||||
]
|
||||
|
||||
debug_dir = None
|
||||
if os.path.isdir("debug"):
|
||||
debug_dir = f"debug/StructureBuilder/{StructureBuilder.DEBUG_ID}"
|
||||
debug_dir = debug_path("StructureBuilder", StructureBuilder.DEBUG_ID)
|
||||
if debug_dir:
|
||||
StructureBuilder.DEBUG_ID += 1
|
||||
os.makedirs(debug_dir, exist_ok=True)
|
||||
with open(f"{debug_dir}/request.txt", "w", encoding="utf-8") as f:
|
||||
f.write(messages[1].content)
|
||||
(debug_dir / "request.txt").write_text(messages[1].content, encoding="utf-8")
|
||||
|
||||
retries_left = self.MAX_RETRIES
|
||||
while retries_left > 0:
|
||||
retries_left -= 1
|
||||
response = self._agent.completion(messages=messages, response_format=_BuildResult)
|
||||
if debug_dir:
|
||||
with open(
|
||||
f"{debug_dir}/{retries_left}-retries-left.txt",
|
||||
"w",
|
||||
(debug_dir / f"{retries_left}-retries-left.txt").write_text(
|
||||
response,
|
||||
encoding="utf-8",
|
||||
) as f:
|
||||
f.write(response)
|
||||
)
|
||||
|
||||
try:
|
||||
result = _BuildResult.model_validate_json(response)
|
||||
|
||||
Reference in New Issue
Block a user