Load response when loading iteration
This commit is contained in:
@@ -28,14 +28,18 @@ class IterationParser:
|
|||||||
"""
|
"""
|
||||||
root = ET.fromstring(content)
|
root = ET.fromstring(content)
|
||||||
context_elem = root.find("context")
|
context_elem = root.find("context")
|
||||||
|
response_elem = root.find("response")
|
||||||
|
|
||||||
if context_elem is None:
|
if context_elem is None:
|
||||||
raise ValueError("Invalid iteration file - missing context")
|
raise ValueError("Invalid iteration file - missing context")
|
||||||
|
if response_elem is None:
|
||||||
|
raise ValueError("Invalid iteration file - missing response")
|
||||||
|
|
||||||
context = ET.fromstring(context_elem.text)
|
context = context_elem.text.strip()
|
||||||
|
response = response_elem.text.strip()
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for elem in context:
|
for elem in ET.fromstring(context):
|
||||||
if elem.tag == "background":
|
if elem.tag == "background":
|
||||||
entries.append(IterationParser._parse_background(elem, work_dir))
|
entries.append(IterationParser._parse_background(elem, work_dir))
|
||||||
elif elem.tag == "parse_error":
|
elif elem.tag == "parse_error":
|
||||||
@@ -51,7 +55,7 @@ class IterationParser:
|
|||||||
elif elem.tag == "write_stdout":
|
elif elem.tag == "write_stdout":
|
||||||
entries.append(IterationParser._parse_write(elem, io_buffer))
|
entries.append(IterationParser._parse_write(elem, io_buffer))
|
||||||
|
|
||||||
return entries
|
return (context, response, entries)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_background(elem: ET.Element, work_dir: Path) -> BackgroundEntry:
|
def _parse_background(elem: ET.Element, work_dir: Path) -> BackgroundEntry:
|
||||||
|
|||||||
@@ -304,10 +304,12 @@ class Api:
|
|||||||
if not content:
|
if not content:
|
||||||
return web.Response(status=400, text="Missing content in request body")
|
return web.Response(status=400, text="Missing content in request body")
|
||||||
|
|
||||||
entries = IterationParser.parse_iteration(content, self._work_dir, self._io_buffer)
|
(context, response, entries) = IterationParser.parse_iteration(content, self._work_dir, self._io_buffer)
|
||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
self._working_memory.add_entry(entry)
|
self._working_memory.add_entry(entry)
|
||||||
|
self._agent.modify_context(context, True)
|
||||||
|
self._agent.response_buffer.set_text(response)
|
||||||
|
|
||||||
return web.Response(status=200)
|
return web.Response(status=200)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user