赞
踩
### 1.2.2、从文件加载 Prompt 模板
- from langchain.prompts import PromptTemplate
-
- template = PromptTemplate.from_file("example_prompt_template.txt")
- print("===Template===")
- print(template)
- print("===Prompt===")
- print(template.format(topic='黑色幽默'))
可以看到这里使用promptTemplate.from_file加载了txt文件,这个文件就是prompt的模板
然后
注意这个:example_prompt_template.txt文件中的内容是:
举一个关于{topic}的例子
这个:
- ===Template===
- input_variables=['topic'] template='举一个关于{topic}的例子'
- ===Prompt===
- 举一个关于黑色幽默的例子
打印出来是上面的效果.
- ### 1.3 输出封装 OutputParser
-
- 自动把 LLM 输出的字符串按指定格式加载。
-
- LangChain 内置的 OutputParser 包括:
-
- - ListParser
- - DatetimeParser
- - EnumParser
- - JsonOutputParser
- - PydanticParser
- - XMLParser
-
- 等等
-
- ### 1.3.1 Pydantic (JSON) Parser
-
- 自动根据 Pydantic 类的定义,生成输出的格式说明
</
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。