From 41b99fb9b080db432aba13f890e35510c55a01aa Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Wed, 9 Oct 2024 22:19:32 +0800 Subject: [PATCH] fix: merge `locals()` with `globals()` for context forwarding --- python/promplate/prompt/template.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/promplate/prompt/template.py b/python/promplate/prompt/template.py index 7e465b2..0651d56 100644 --- a/python/promplate/prompt/template.py +++ b/python/promplate/prompt/template.py @@ -3,6 +3,7 @@ from functools import cached_property, partial from pathlib import Path from sys import path as sys_path +from sys import version_info from textwrap import dedent from typing import TYPE_CHECKING, Any, Literal, Protocol @@ -87,7 +88,8 @@ def _on_special_token(self, token, sync: bool): @staticmethod def _make_context(text: str): """generate context parameter if specified otherwise use locals() by default""" - + if version_info >= (3, 13): + return f"globals() | locals() | dict({text[text.index(' ') + 1:]})" if " " in text else "globals() | locals()" return f"locals() | dict({text[text.index(' ') + 1:]})" if " " in text else "locals()" def compile(self, sync=True, indent_str="\t"):