-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: update langchain imports for v1.0+ compatibility #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update langchain imports for v1.0+ compatibility #1033
Conversation
- Change ResponseSchema and StructuredOutputParser imports to use langchain_classic.output_parsers instead of langchain_core.output_parsers - Change create_extraction_chain import to use langchain_classic.chains instead of langchain.chains - Add langchain-classic>=1.0.0 as explicit dependency - Relax async-timeout requirement to >=4.0.0 for compatibility Fixes ScrapeGraphAI#1017 Signed-off-by: majiayu000 <[email protected]>
The PromptTemplate expects 'content' variable but the code was passing 'context', causing KeyError during graph execution. Fixes ScrapeGraphAI#995 Signed-off-by: majiayu000 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR updates the codebase to be compatible with LangChain v1.0+ by migrating deprecated imports to langchain-classic and fixing a variable name mismatch that was causing runtime errors.
Key Changes:
- Migrated deprecated LangChain imports (
ResponseSchema,StructuredOutputParser,create_extraction_chain) to uselangchain-classicpackage - Fixed variable name inconsistency in
generate_answer_node_k_level.pywhere template expectscontentbut code was passingcontext - Added
langchain-classic>=1.0.0as explicit dependency and relaxedasync-timeoutversion constraint for better compatibility
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
scrapegraphai/nodes/generate_code_node.py |
Updated imports to use langchain_classic.output_parsers for ResponseSchema and StructuredOutputParser |
scrapegraphai/builders/graph_builder.py |
Updated import to use langchain_classic.chains for create_extraction_chain; minor formatting improvement |
scrapegraphai/nodes/generate_answer_node_k_level.py |
Fixed variable name from context to content in three locations to match template expectations |
pyproject.toml |
Added langchain-classic>=1.0.0 dependency and relaxed async-timeout requirement from >=5.0.1 to >=4.0.0 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
VinciGit00
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Great work on this PR! The changes correctly address LangChain v1.0+ compatibility issues. Here's my assessment:
✅ Approved Changes
-
Import Updates: All import changes from
langchain.chainsandlangchain_core.output_parserstolangchain_classicequivalents are correct and necessary for LangChain v1.0+ compatibility. -
Bug Fix: The variable name fix in
generate_answer_node_k_level.py(changingcontexttocontent) is correct. I verified that all templates use{content}, not{context}, so this was indeed a bug that needed fixing. -
Dependency Management: Adding
langchain-classic>=1.0.0is appropriate. The relaxation ofasync-timeoutversion seems reasonable, though worth verifying it doesn't break anything. -
Code Quality: The formatting improvements are welcome.
📝 Testing Notes
I attempted to test the imports but encountered dependency conflicts in the local environment (expected in a mixed environment). However, the changes are syntactically correct and follow the official LangChain migration path for v1.0+.
✅ Recommendation: Approve
This PR correctly addresses the compatibility issues mentioned in #1017 and #995. The changes are minimal, focused, and follow best practices for LangChain v1.0+ migration.
Ready to merge! 🚀
|
🎉 This PR is included in version 1.71.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Summary
ResponseSchemaandStructuredOutputParserimports to uselangchain_classic.output_parserscreate_extraction_chainimport to uselangchain_classic.chainslangchain-classic>=1.0.0as explicit dependencyasync-timeoutrequirement to>=4.0.0for compatibilitygenerate_answer_node_k_level.py: usecontentinstead ofcontextFixes #1017
Fixes #995
Changes
scrapegraphai/nodes/generate_code_node.pylangchain_classic.output_parsersscrapegraphai/builders/graph_builder.pylangchain_classic.chainsscrapegraphai/nodes/generate_answer_node_k_level.pycontentvariable instead ofcontextpyproject.tomllangchain-classicdependency, relaxasync-timeoutTest plan