Skip to content

Commit

Permalink
Update loader.py (#32)
Browse files Browse the repository at this point in the history
fix import bugs
  • Loading branch information
liuxukun2000 authored Jul 9, 2023
1 parent e51eec6 commit 36a7139
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gentopia/assembler/loader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
from pathlib import Path
from typing import Any, IO
from gentopia.prompt import *
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 36a7139

Please # to comment.