diff --git a/aiopslab/orchestrator/parser.py b/aiopslab/orchestrator/parser.py index 0e81a39a..b93b41ef 100644 --- a/aiopslab/orchestrator/parser.py +++ b/aiopslab/orchestrator/parser.py @@ -13,6 +13,24 @@ class ResponseParser: def __init__(self): pass + def validate(self, response: str): + actions = re.findall(r"```\s*\n(.*?)\n```", response, re.DOTALL) + if len(actions) != 1: + raise ResponseParsingError(""" +Format validation failure. Only have one pair of three ticks in your block and check the ticks. +Correct example 1: +I should run: +``` +exec_shell("ls") +``` + +Correct example 2: +Check k8s info +``` +exec_shell("kubectl get services --all-namespaces") +``` + """) + def parse(self, response: str) -> dict: """Parses the response string to extract the API name and arguments. @@ -22,6 +40,7 @@ def parse(self, response: str) -> dict: Returns: dict: The parsed API name and arguments. """ + self.validate(response) code_block = self.extract_codeblock(response) context = self.extract_context(response) api_name = self.parse_api_name(code_block)