From 36a713914c33a49d7ff0bbaeac43c21e79e7677e Mon Sep 17 00:00:00 2001 From: xukunliu2000 <57486241+liuxukun2000@users.noreply.github.com> Date: Sun, 9 Jul 2023 10:23:20 +0800 Subject: [PATCH] Update loader.py (#32) fix import bugs --- gentopia/assembler/loader.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gentopia/assembler/loader.py b/gentopia/assembler/loader.py index 1d3296e..ab5d470 100755 --- a/gentopia/assembler/loader.py +++ b/gentopia/assembler/loader.py @@ -1,3 +1,4 @@ +import importlib from pathlib import Path from typing import Any, IO from gentopia.prompt import * @@ -26,7 +27,12 @@ def include(self, node: yaml.Node) -> Any: def prompt(self, node: yaml.Node) -> Any: prompt = self.construct_scalar(node) - prompt_cls = eval(prompt) + if '.' in prompt: + _path = prompt.split('.') + module = importlib.import_module('.'.join(_path[:-1])) + prompt_cls = getattr(module, _path[-1]) + else: + prompt_cls = eval(prompt) assert issubclass(prompt_cls.__class__, PromptTemplate) return prompt_cls