dify/api/core/prompt/prompt_builder.py

11 lines
387 B
Python
Raw Normal View History

from core.prompt.prompt_template import PromptTemplateParser
2023-05-15 08:51:32 +08:00
class PromptBuilder:
@classmethod
def parse_prompt(cls, prompt: str, inputs: dict) -> str:
prompt_template = PromptTemplateParser(prompt)
prompt_inputs = {k: inputs[k] for k in prompt_template.variable_keys if k in inputs}
prompt = prompt_template.format(prompt_inputs)
return prompt