当前位置:   article > 正文

人工智能_大模型032_LangChain002_从文件加载prompt_输出封装OutputParser_加载PDF等文档_向量数据库与向量检索---人工智能工作笔记0167

人工智能_大模型032_LangChain002_从文件加载prompt_输出封装OutputParser_加载PDF等文档_向量数据库与向量检索---人工智能工作笔记0167

### 1.2.2、从文件加载 Prompt 模板

  1. from langchain.prompts import PromptTemplate
  2. template = PromptTemplate.from_file("example_prompt_template.txt")
  3. print("===Template===")
  4. print(template)
  5. print("===Prompt===")
  6. print(template.format(topic='黑色幽默'))

可以看到这里使用promptTemplate.from_file加载了txt文件,这个文件就是prompt的模板

然后

注意这个:example_prompt_template.txt文件中的内容是:

举一个关于{topic}的例子

这个:

  1. ===Template===
  2. input_variables=['topic'] template='举一个关于{topic}的例子'
  3. ===Prompt===
  4. 举一个关于黑色幽默的例子

打印出来是上面的效果.

  1. ### 1.3 输出封装 OutputParser
  2. 自动把 LLM 输出的字符串按指定格式加载。
  3. LangChain 内置的 OutputParser 包括:
  4. - ListParser
  5. - DatetimeParser
  6. - EnumParser
  7. - JsonOutputParser
  8. - PydanticParser
  9. - XMLParser
  10. 等等
  11. ### 1.3.1 Pydantic (JSON) Parser
  12. 自动根据 Pydantic 类的定义,生成输出的格式说明
</
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/688108
推荐阅读
相关标签
  

闽ICP备14008679号