From 53fd38eb5fc25f85a5fb24f0588a863f0ff5bd6b Mon Sep 17 00:00:00 2001 From: Langfun Authors Date: Tue, 10 Oct 2023 15:52:08 -0700 Subject: [PATCH] Surface `cleanup_json` to be publicly accessible. PiperOrigin-RevId: 572389961 --- langfun/core/structured/schema.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/langfun/core/structured/schema.py b/langfun/core/structured/schema.py index 92f6de61..62444aac 100644 --- a/langfun/core/structured/schema.py +++ b/langfun/core/structured/schema.py @@ -604,7 +604,7 @@ def parse(self, text: str, schema: Schema | None = None, **kwargs) -> Any: """Parse a JSON string into a structured object.""" del schema try: - text = self._cleanup_json(text) + text = self.cleanup_json(text) v = pg.from_json_str(text) except Exception as e: raise JsonError(text, e) # pylint: disable=raise-missing-from @@ -616,7 +616,7 @@ def parse(self, text: str, schema: Schema | None = None, **kwargs) -> Any: )) return v['result'] - def _cleanup_json(self, json_str: str) -> str: + def cleanup_json(self, json_str: str) -> str: """Clean up the LM responded JSON string.""" # Treatments: # 1. Extract the JSON string with a top-level dict from the response.