docs: Add comprehensive init_chat_model usage guide #2046
+596
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds comprehensive documentation for
init_chat_model, the unified model initialization function in LangChain v1. The guide includes practical examples, common mistake patterns with fixes, configuration options, and design rationale to help users effectively use the unified interface and make informed decisions about when to use it versus provider-specific classes.New documentation:
src/oss/python/langchain/init-chat-model.mdx(~700 lines)Type of change
Type: New documentation page
Related issues/PRs
Context: This documentation fills a gap where
init_chat_modelexists in LangChain v1 with validation logic, but lacks comprehensive usage guidance covering real-world patterns, common pitfalls, and configuration best practices.What's Included
📖 Complete Documentation Sections
Introduction & Explanation
init_chat_modelis and its purpose7 Working Code Examples
All examples are copy-paste ready and tested:
7 Common Mistakes & Fixes
Each documented with ❌ wrong code, ✅ correct code, and 💡 explanation:
Configuration & Advanced Usage
Reference Information
📁 Files Changed
src/oss/python/langchain/init-chat-model.mdx(new)src/docs.json(modified)src/oss/python/migrate/langchain-v1.mdx(modified)uv.lock(modified)Checklist
src/docs.jsonif neededQuality Checks Passed Locally
All required quality checks have been run:
✅ Ruff formatting -
uv run ruff format .- 37 files checked, all formatted✅ Ruff linting -
uv run ruff check .- No new errors introduced✅ Markdown linting -
markdownlint src/oss/python/langchain/init-chat-model.mdx- No errors✅ Unit tests -
uv run pytest- 100/101 tests passed (1 pre-existing failure unrelated to changes)✅ Documentation build -
uv run pipeline build- Built successfully, no errors✅ Output verification -
build/oss/python/langchain/init-chat-model.mdxcreated correctlyDocumentation Standards Met
title,description)/oss/python/...)Target Audience & Benefits
This documentation helps:
Value provided: