可以看到github上,langchain的star已经超过60k了,因此可以看出其火爆程度。
langchain的一个特点是链式调用。
按照官网的文档,langchain的作用领域可以分为六块,复杂度递增:
1、LLMs and Prompts 2、Chains 3、Data Augmented Generation: 4、Agents 5、Memory 6、Evaluation
langchain的模块,也可以分为六大模块: 1、Model I/O 2、Retrieval 3、Chains 4、Agents 5、Memory 6、Callbacks
ModelIO
可以允许使用不同的语言模型,并且可以提取输出功率内容进行转换。
prompts
Prompt templates 提供了prompt模版 使用同一个模版,可以队不同的大语言模型进行操作,实际上就是屏蔽了不同大语言模型api的差异。
from langchain import PromptTemplate
prompt_template = PromptTemplate.from_template(
"Tell me a {adjective} joke about {content}."
)
prompt_template.format(adjective="funny", content="chickens")
这里就类似于python本身就是字符串中加入参数一样。
ChatPromptTemplate,对应的是调用openai的Chat Completions的Api。
from langchain.prompts import ChatPromptTemplate
template = ChatPromptTemplate.from_messages([
("system", "You are a helpful AI bot. Your name is {name}."),
("human", "Hello, how are you doing?"),
("ai", "I'm doing well, thanks!"),
("human", "{user_input}"),
])
messages = template.format_messages(
name="Bob",
user_input="What is your name?"
)
Retrieval
Chains
Agents
Memory
#Callbacks