From bd13f3facb8032450bc543630a91424ed3142aab Mon Sep 17 00:00:00 2001 From: duckduckgrayduck <102841251+duckduckgrayduck@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:53:57 -0500 Subject: [PATCH] Add value filtering --- config.yaml | 6 +++++- main.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config.yaml b/config.yaml index ac2dcc2..6f3abf9 100644 --- a/config.yaml +++ b/config.yaml @@ -20,7 +20,11 @@ properties: filter_key: title: "Filter Key" type: string - description: "If you need to narrow down the document set further, provide a key name you want to filter by" + description: "If you need to narrow down the document set further, provide a key name you want to filter by. If value isn't also specified, then it will filter on any documents that have that key." + filter_value: + title: "Filter Value" + type: string + description: "If you want to provide a specific key/value pair to narrow on, provide the value here and the key in filter key. " prompt: title: "Prompt" type: string diff --git a/main.py b/main.py index 370c4e4..a986e4b 100644 --- a/main.py +++ b/main.py @@ -16,11 +16,17 @@ def main(self): prompt = self.data.get("prompt") limiter = self.data.get("limiter") filter_key = self.data.get("filter_key") + filter_value = self.data.get("filter_value") if filter_key is not None: - documents = self.client.documents.search( - f"+project:{proj_id} -data_{key_name}:* data_{filter_key}:*" - ) + if filter_value is not None: + documents = self.client.documents.search( + f"+project:{proj_id} -data_{key_name}:* data_{filter_key}:{filter_value}" + ) + else: + documents = self.client.documents.search( + f"+project:{proj_id} -data_{key_name}:* data_{filter_key}:*" + ) else: documents = self.client.documents.search( f"+project:{proj_id} -data_{key_name}:*"