使用LangChain快速搭建自己的大模型产品

使用LangChain框架的核心目标是连接多种大语言模型(如ChatGP、LLaMA等)和外部资源(如Google、Wikipedia、Notion及Wolffram等),提供抽象组件和工具以在文本输入和输出之间进行接口处理。

一、langChain安装

官方文档地址
langchain

pip install langchain
pip install langchain_community
pip install -U langchain-openai

二、简单使用

import langchain
langchain.__version__

from langchain import PromptTemplate
template = """
You are a naming consultant for new companies.
What is a good name for a company that makes {product}?
"""

prompt = PromptTemplate.from_template(template)
print(prompt)
print(prompt.format(product="colorful socks"))

# input_variables=['product'] template='\nYou are a naming consultant for new companies.\nWhat is a good name for a company that makes {product}?\n'

# You are a naming consultant for new companies.
# What is a good name for a company that makes colorful socks?

三、LangChain框架核心模块

1. 模型输入/输出(Model I/O) :与大语言模型交互的接口

  • LLMs:大语言模型
  • Chat Models:一般基于 LLMs,但按对话结构重新封装
  • PromptTemple:提示词模板
  • OutputParser:解析输出

2. 数据连接(Data connection):与特定应用程序的数据进行交互的接口

  • Document Loaders:各种格式文件的加载器
  • Document Transformers:对文档的常用操作,如:split, filter, translate, extract metadata, etc
  • Text Embedding Models:文本向量化表示,用于检索等操作(啥意思?别急,后面详细讲)
  • Verctorstores: (面向检索的)向量的存储
  • Retrievers: 向量的检索

3. 记忆(Memory):用于在链的多次运行之间持久化应用程序状态

  • Memory:这里不是物理内存,从文本的角度,可以理解为“上文”、“历史记录”或者说“记忆力”的管理

4. 架构

  • Chain:实现一个功能或者一系列顺序功能组合
  • Agent:根据用户输入,自动规划执行步骤,自动选择每步需要的工具,最终完成用户指定的功能
    • Tools:调用外部功能的函数,例如:调 google 搜索、文件 I/O、Linux Shell 等等
    • Toolkits:操作某软件的一组工具集,例如:操作 DB、操作 Gmail 等等

5. 回调 (Callbacks):用于记录和流式传输任何链式组件的中间步骤

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值