Added docker support
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validator
|
||||
|
||||
from agent import Agent, AgentMessage
|
||||
from paths import debug_path, prompt_path
|
||||
from structure_builder import ImageElement, Structure, StructureElement
|
||||
from windowizer import Window, Windowizer
|
||||
|
||||
@@ -39,8 +39,10 @@ class StructureRefiner:
|
||||
def __init__(self, agent: Agent, windowizer: Windowizer[StructureElement]) -> None:
|
||||
self._agent = agent
|
||||
self._windowizer = windowizer
|
||||
with open("prompts/structure_refiner.md", "r", encoding="utf-8") as f:
|
||||
self._system_prompt = AgentMessage(content=f.read(), role="system")
|
||||
self._system_prompt = AgentMessage(
|
||||
content=prompt_path("structure_refiner.md").read_text(encoding="utf-8"),
|
||||
role="system",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _validate_result(
|
||||
@@ -69,13 +71,10 @@ class StructureRefiner:
|
||||
),
|
||||
]
|
||||
|
||||
debug_dir = None
|
||||
if os.path.isdir("debug"):
|
||||
debug_dir = f"debug/StructureRefiner/{StructureRefiner.DEBUG_ID}"
|
||||
debug_dir = debug_path("StructureRefiner", StructureRefiner.DEBUG_ID)
|
||||
if debug_dir:
|
||||
StructureRefiner.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:
|
||||
@@ -85,12 +84,10 @@ class StructureRefiner:
|
||||
response_format=_RefineResult,
|
||||
)
|
||||
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 = _RefineResult.model_validate_json(response)
|
||||
|
||||
Reference in New Issue
Block a user