def refine_struct_format()

in src/models/struxgpt_v2.py [0:0]


    def refine_struct_format(self, raw_query: str, raw_response: str, format: Literal["json", "yaml"],
                                   return_json: bool = True, verbose=False):
        refine_prompt = (
            f"Correct any syntax error in the following {format.upper()} snippet and format it properly. "
            f"Ensure that the corrected {format.upper()} is valid and retains the same information as the original. "
            f"The corrected {format.upper()} should be displayed as code, starting with \"```{format}\" and ending with \"```\".\n\n"
            f"Here is the {format.upper()} snippet to correct:\n"
            f"{raw_response}"
        )
        try:
            refined_response = self.call_model(refine_prompt)
            struct_res = StructItem(self.scfg, raw_query, refined_response, single_sent_ok=True)
            assert struct_res.valid
            if verbose:
                print(f'Successfully refined {format.upper()} response.')
            return struct_res.to_json() if return_json else struct_res
        except:
            if verbose:
                print(f'Failed to refine {format.upper()} response. Try to structurize again.')
            # print(refined_response)
            return self.refine_struct_result(raw_query, return_json=return_json)