itemgetter:返回一個函數,函數取輸入dict的某個指定key
Runnable 的基本方法有 invoke、 batch、 await、 ainvoke、 abatch 同步轉異步
Runnable 還具有的方法:bind、 with_config。 input_schema 屬性、output_schema 屬性
with_retry方法:失敗重試
也可以啟動調試機制
config_schema() 方法:可接受的配置類型,指定為一個pydantic模型。
RunnableBinding類:用額外的功能封裝一個Runnable。可運行的裝飾器。包含方法:bind(綁定kwargs)、with_config(綁定配置)等等
RunnableLambda 將python函數轉為Runnable
RunnableParallel 并行計算,并賦值一個key
RunnableAssign 一般與RunnableParallel結合,將輸入數據復制保留,將產生的數據用 RunnableParallel的key記錄下來
assign: 將上面的進行合并處理 xx.assign = xx | RunnableAssign(RunnableParallel(kwargs))
ICEL:聲明式的方法。 主要的組合原語是 RunnableSequence 【順序調用】和 RunnableParallel 【并發調用】。
ChatPromptTemplate 聊天模版、示例:
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([("system", "You are a world class technical documentation writer."),("user", "{input}")
])
StrOutputParser類 將 Message定向解析
模型:ChatModels、 LLMs
ChatModels: 輸入是聊天消息列表、輸出是AI消息
LLMs:純文本補全模型
提示模板:ChatPromptTemplates
BaseExampleSelector 示例選擇器
輸出解析器 CommaSeparatedListOutputParser 解析逗號分隔值
partial 部分參數預先被填充
定義工具schemas: Pydantic類