From 2a61f43c9952406a295483b3b7e5e826dbfd5176 Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Wed, 14 Aug 2024 10:27:22 -0700 Subject: [PATCH] Fix extraction --- griptape/engines/extraction/json_extraction_engine.py | 2 +- griptape/templates/engines/extraction/json/user.j2 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/griptape/engines/extraction/json_extraction_engine.py b/griptape/engines/extraction/json_extraction_engine.py index 56815bc06..5fc64f838 100644 --- a/griptape/engines/extraction/json_extraction_engine.py +++ b/griptape/engines/extraction/json_extraction_engine.py @@ -18,7 +18,7 @@ @define class JsonExtractionEngine(BaseExtractionEngine): - JSON_PATTERN = r"(?s)[^\[]*(\[.*\])" + JSON_PATTERN = r"(?s)(\{.*?\}|\[.*?\])" template_schema: dict = field(default=Factory(dict), kw_only=True) system_template_generator: J2 = field( diff --git a/griptape/templates/engines/extraction/json/user.j2 b/griptape/templates/engines/extraction/json/user.j2 index 984977d9a..00e162d15 100644 --- a/griptape/templates/engines/extraction/json/user.j2 +++ b/griptape/templates/engines/extraction/json/user.j2 @@ -1,4 +1,4 @@ -Extract information from the Text based on the Extraction Template JSON Schema into an array of JSON objects. +Extract information from the Text based on the Extraction Template JSON Schema into valid JSON. Text: """{{ text }}""" -JSON array: +JSON: