Metadata variable value fix (#16665)

This commit is contained in:
Jyong 2025-03-25 09:07:11 +08:00 committed by GitHub
parent 360986f38d
commit 86a1859d02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -900,7 +900,10 @@ class DatasetRetrieval:
return str(inputs.get(key, f"{{{{{key}}}}}"))
pattern = re.compile(r"\{\{(\w+)\}\}")
return pattern.sub(replacer, text)
output = pattern.sub(replacer, text)
if isinstance(output, str):
output = re.sub(r"[\r\n\t]+", " ", output).strip()
return output
def _automatic_metadata_filter_func(
self, dataset_ids: list, query: str, tenant_id: str, user_id: str, metadata_model_config: ModelConfig

View File

@ -1,5 +1,6 @@
import json
import logging
import re
import time
from collections import defaultdict
from collections.abc import Mapping, Sequence
@ -360,8 +361,13 @@ class KnowledgeRetrievalNode(LLMNode):
if isinstance(expected_value, str):
expected_value = self.graph_runtime_state.variable_pool.convert_template(
expected_value
).text
).value[0]
if expected_value.value_type == "number":
expected_value = expected_value.value
elif expected_value.value_type == "string":
expected_value = re.sub(r"[\r\n\t]+", " ", expected_value.text).strip()
else:
raise ValueError("Invalid expected metadata value type")
filters = self._process_metadata_filter_func(
condition.comparison_operator, metadata_name, expected_value, filters
)