Han

Life is a gift, we should celebrate it. We have to dance to show how grateful we are to be alive.

0%

Langchain

langchain技术要点

Langchain是利用大语言模型开发下游应用的最优实现

  • Langchain conceptual 理解

  • LC Documentation

  • ​ 高度集成:支持各种外部文件,数据库,文件系统等等,与大语言模型进行结合

  • 执行(agent):使得大语言模型可以通过决策(decision making)和环境交互

核心:

Agents and Chains:

Chains代表执行复杂的集成任务,例如发起http请求,和数据库交互,实现网页搜索等等。

Agent根据不同的问题,决定执行下游chain

**Prompt:内部的实现是通过定制化的prompt多次与大语言模型进行交互,使得其具备逻辑思考,动作执行的能力

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# flake8: noqa
PREFIX = """Answer the following questions as best you can. You have access to the following tools:"""
FORMAT_INSTRUCTIONS = """Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question"""
SUFFIX = """Begin!

Question: {input}
Thought:{agent_scratchpad}"""

Prompt范式:MRKL agent

MRKL 格式

各种Prompt

Vecstore

image-20230725123055456

Vecstore向量库

Langchain核心组件 CookBook:

https://github.com/gkamradt/langchain-tutorials/blob/main/LangChain%20Cookbook%20Part%201%20-%20Fundamentals.ipynb

Langchain具体的下游应用场景

https://github.com/gkamradt/langchain-tutorials/blob/main/LangChain%20Cookbook%20Part%202%20-%20Use%20Cases.ipynb

Langchain Handbook

https://github.com/pinecone-io/examples/blob/master/generation/langchain/handbook/03-langchain-conversational-memory.ipynb

具体案例(和数据库进行SQL交互) 数据库连接–>SQL生成–>SQL执行

https://python.langchain.com/docs/integrations/toolkits/sql_database