Create

Sign in to ReadmeX

or

How we handle your data: Privacy Policy

ReadmeX

Your AI reading companion

What would you like to catch up on?

Pick a briefing, or ask your own question.

Your community and people briefings stay personal to you.

Story

LangChain ChatModel Creation and Invocation Guide

AI summary

A Juejin learning note explains that LangChain chat models implement the Runnable interface and can be created by instantiating provider classes or through init_chat_model with a provider:model-name identifier. It covers invoke, stream and batch calls, along with the asynchronous ainvoke, astream and abatch variants, and notes that true incremental streaming depends on provider support.

In-depth insight

The guide gives developers a concise reference for using one model interface across providers, including synchronous, streaming, batch and asynchronous invocation patterns.

1. 核心认知:模型是 Runnable

在 LangChain 中,聊天模型(ChatModel)不是孤立的存在,它实现了 Runnable 接口。这意味着你学过的 Tool 调用方式——invoke、stream、batch——同样适用于模型本身。理解这一点,后续所有调用方式都是同一个协议的变体。


2. 创建模型的两种方式

方式一:直接实例化提供商类

最直观的方式,需要安装对应的集成包:

#LangChain#ChatOpenAI#ChatAnthropic#ChatGoogleGenerativeAI#ChatOllama#LangSmith

Original · 3 min readRead the original
Group chat

No comments yet. Start the conversation.