Skip to content

Python scraper based on AI

fix: update langchain imports for v1.0+ compatibility

majiayu000621d3a5bba6c
diff --git a/pyproject.toml b/pyproject.toml
index 704c4bf1..a7edfc13 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -11,6 +11,7 @@ authors = [
dependencies = [
"langchain>=1.2.0",
+ "langchain-classic>=1.0.0",
"langchain-openai>=1.1.6",
"langchain-mistralai>=1.1.1",
"langchain_community>=0.3.31",
@@ -26,7 +27,7 @@ dependencies = [
"playwright>=1.57.0",
"undetected-playwright>=0.3.0",
"semchunk>=3.2.5",
- "async-timeout>=5.0.1",
+ "async-timeout>=4.0.0",
"simpleeval>=1.0.3",
"jsonschema>=4.25.1",
"duckduckgo-search>=8.1.1",
diff --git a/scrapegraphai/builders/graph_builder.py b/scrapegraphai/builders/graph_builder.py
index 1179ebe7..3e52ec17 100644
--- a/scrapegraphai/builders/graph_builder.py
+++ b/scrapegraphai/builders/graph_builder.py
@@ -2,7 +2,7 @@
GraphBuilder Module
"""
-from langchain.chains import create_extraction_chain
+from langchain_classic.chains import create_extraction_chain
from langchain_community.chat_models import ErnieBotChat
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
@@ -113,7 +113,9 @@ class GraphBuilder:
{nodes_description}
Based on the user's input: "{input}", identify the essential nodes required for the task and suggest a graph configuration that outlines the flow between the chosen nodes.
- """.format(nodes_description=self.nodes_description, input="{input}")
+ """.format(
+ nodes_description=self.nodes_description, input="{input}"
+ )
extraction_prompt = ChatPromptTemplate.from_template(
create_graph_prompt_template
)
diff --git a/scrapegraphai/nodes/generate_code_node.py b/scrapegraphai/nodes/generate_code_node.py
index f3b25218..e99c6754 100644
--- a/scrapegraphai/nodes/generate_code_node.py
+++ b/scrapegraphai/nodes/generate_code_node.py
@@ -12,10 +12,10 @@ from typing import Any, Dict, List, Optional
from bs4 import BeautifulSoup
from jsonschema import ValidationError as JSONSchemaValidationError
from jsonschema import validate
-from langchain_core.output_parsers import ResponseSchema, StructuredOutputParser
-from langchain_core.prompts import PromptTemplate
+from langchain_classic.output_parsers import ResponseSchema, StructuredOutputParser
from langchain_community.chat_models import ChatOllama
from langchain_core.output_parsers import StrOutputParser
+from langchain_core.prompts import PromptTemplate
from ..prompts import TEMPLATE_INIT_CODE_GENERATION, TEMPLATE_SEMANTIC_COMPARISON
from ..utils import (