참고소스 수정본

This commit is contained in:
LASTA_DEV01\lasta
2026-05-12 19:40:31 +09:00
parent 0f34a451fc
commit 2e9204243d
8708 changed files with 3259488 additions and 869 deletions

View File

@@ -0,0 +1,25 @@
import re
from guardrails.classes.templating.constants_container import ConstantsContainer
from guardrails.classes.templating.namespace_template import NamespaceTemplate
# TODO: Move this to guardrails/constants/__init__.py
# Singleton instance created on import/init
constants = ConstantsContainer()
# TODO: Consolidate this and guardrails/utils/prompt_utils.py
# into guardrails/utils/templating_utils.py
def substitute_constants(text):
"""Substitute constants in the prompt."""
# Substitute constants by reading the constants file.
# Regex to extract all occurrences of ${gr.<constant_name>}
matches = re.findall(r"\${gr\.(\w+)}", text)
# Substitute all occurrences of ${gr.<constant_name>}
# with the value of the constant.
for match in matches:
template = NamespaceTemplate(text)
mapping = {f"gr.{match}": constants[match]}
text = template.safe_substitute(**mapping)
return text