Skip to content

Python scraper based on AI

Add code generator examples

Matteo Vedovatifb879012d32e
diff --git a/examples/anthropic/code_generator_graph_anthropic.py b/examples/anthropic/code_generator_graph_anthropic.py
new file mode 100644
index 00000000..49bd413d
--- /dev/null
+++ b/examples/anthropic/code_generator_graph_anthropic.py
@@ -0,0 +1,60 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+anthropic_key = os.getenv("ANTHROPIC_API_KEY")
+
+graph_config = {
+ "llm": {
+ "api_key":anthropic_key,
+ "model": "anthropic/claude-3-haiku-20240307",
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
diff --git a/examples/azure/code_generator_graph_azure.py b/examples/azure/code_generator_graph_azure.py
new file mode 100644
index 00000000..79be4534
--- /dev/null
+++ b/examples/azure/code_generator_graph_azure.py
@@ -0,0 +1,58 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+graph_config = {
+ "llm": {
+ "api_key": os.environ["AZURE_OPENAI_KEY"],
+ "model": "azure_openai/gpt-3.5-turbo",
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/bedrock/code_generator_graph_bedrock.py b/examples/bedrock/code_generator_graph_bedrock.py
new file mode 100644
index 00000000..2998873b
--- /dev/null
+++ b/examples/bedrock/code_generator_graph_bedrock.py
@@ -0,0 +1,60 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+
+graph_config = {
+ "llm": {
+ "client": "client_name",
+ "model": "bedrock/anthropic.claude-3-sonnet-20240229-v1:0",
+ "temperature": 0.0
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/deepseek/code_generator_graph_deepseek.py b/examples/deepseek/code_generator_graph_deepseek.py
new file mode 100644
index 00000000..17b1a970
--- /dev/null
+++ b/examples/deepseek/code_generator_graph_deepseek.py
@@ -0,0 +1,60 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+deepseek_key = os.getenv("DEEPSEEK_APIKEY")
+
+graph_config = {
+ "llm": {
+ "model": "deepseek/deepseek-chat",
+ "api_key": deepseek_key,
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/ernie/code_generator_graph_ernie.py b/examples/ernie/code_generator_graph_ernie.py
new file mode 100644
index 00000000..1545238b
--- /dev/null
+++ b/examples/ernie/code_generator_graph_ernie.py
@@ -0,0 +1,62 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+openai_key = os.getenv("OPENAI_APIKEY")
+
+graph_config = {
+ "llm": {
+ "model": "ernie/ernie-bot-turbo",
+ "ernie_client_id": "<ernie_client_id>",
+ "ernie_client_secret": "<ernie_client_secret>",
+ "temperature": 0.1
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/fireworks/code_generator_graph_fireworks.py b/examples/fireworks/code_generator_graph_fireworks.py
new file mode 100644
index 00000000..9bbec7f2
--- /dev/null
+++ b/examples/fireworks/code_generator_graph_fireworks.py
@@ -0,0 +1,60 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+fireworks_api_key = os.getenv("FIREWORKS_APIKEY")
+
+graph_config = {
+ "llm": {
+ "api_key": fireworks_api_key,
+ "model": "fireworks/accounts/fireworks/models/mixtral-8x7b-instruct"
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/google_genai/code_generator_graph_gemini.py b/examples/google_genai/code_generator_graph_gemini.py
new file mode 100644
index 00000000..4d16fdff
--- /dev/null
+++ b/examples/google_genai/code_generator_graph_gemini.py
@@ -0,0 +1,60 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+gemini_key = os.getenv("GOOGLE_APIKEY")
+
+graph_config = {
+ "llm": {
+ "api_key": gemini_key,
+ "model": "google_genai/gemini-pro",
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/google_vertexai/code_generator_graph_vertex.py b/examples/google_vertexai/code_generator_graph_vertex.py
new file mode 100644
index 00000000..0d1399ea
--- /dev/null
+++ b/examples/google_vertexai/code_generator_graph_vertex.py
@@ -0,0 +1,60 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+gemini_key = os.getenv("GOOGLE_APIKEY")
+
+graph_config = {
+ "llm": {
+ "api_key": gemini_key,
+ "model": "google_vertexai/gemini-1.5-pro",
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/groq/code_generator_graph_groq.py b/examples/groq/code_generator_graph_groq.py
new file mode 100644
index 00000000..1f7d6b37
--- /dev/null
+++ b/examples/groq/code_generator_graph_groq.py
@@ -0,0 +1,61 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+groq_key = os.getenv("GROQ_APIKEY")
+
+graph_config = {
+ "llm": {
+ "model": "groq/gemma-7b-it",
+ "api_key": groq_key,
+ "temperature": 0
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/huggingfacehub/code_generator_graph_huggingfacehub.py b/examples/huggingfacehub/code_generator_graph_huggingfacehub.py
new file mode 100644
index 00000000..085df3eb
--- /dev/null
+++ b/examples/huggingfacehub/code_generator_graph_huggingfacehub.py
@@ -0,0 +1,71 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+from langchain_community.llms import HuggingFaceEndpoint
+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')
+
+repo_id = "mistralai/Mistral-7B-Instruct-v0.2"
+
+llm_model_instance = HuggingFaceEndpoint(
+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN
+)
+
+embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(
+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"
+)
+
+graph_config = {
+ "llm": {
+ "model_instance": llm_model_instance
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/local_models/code_generator_graph_ollama.py b/examples/local_models/code_generator_graph_ollama.py
new file mode 100644
index 00000000..9246e952
--- /dev/null
+++ b/examples/local_models/code_generator_graph_ollama.py
@@ -0,0 +1,61 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+
+graph_config = {
+ "llm": {
+ "model": "ollama/llama3",
+ "temperature": 0,
+ "format": "json",
+ "base_url": "http://localhost:11434",
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/mistral/code_generator_graph_mistral.py b/examples/mistral/code_generator_graph_mistral.py
new file mode 100644
index 00000000..4abdf1f5
--- /dev/null
+++ b/examples/mistral/code_generator_graph_mistral.py
@@ -0,0 +1,60 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+mistral_key = os.getenv("MISTRAL_API_KEY")
+
+graph_config = {
+ "llm": {
+ "api_key": mistral_key,
+ "model": "mistralai/open-mistral-nemo",
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/moonshot/code_generator_graph_moonshot.py b/examples/moonshot/code_generator_graph_moonshot.py
new file mode 100644
index 00000000..11f9fb47
--- /dev/null
+++ b/examples/moonshot/code_generator_graph_moonshot.py
@@ -0,0 +1,67 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from langchain_community.chat_models.moonshot import MoonshotChat
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+llm_instance_config = {
+ "model": "moonshot-v1-8k",
+ "base_url": "https://api.moonshot.cn/v1",
+ "moonshot_api_key": os.getenv("MOONLIGHT_API_KEY"),
+}
+
+llm_model_instance = MoonshotChat(**llm_instance_config)
+
+graph_config = {
+ "llm": {
+ "model_instance": llm_model_instance,
+ "model_tokens": 10000
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/nemotron/code_generator_graph_nemotron.py b/examples/nemotron/code_generator_graph_nemotron.py
new file mode 100644
index 00000000..1f0ea276
--- /dev/null
+++ b/examples/nemotron/code_generator_graph_nemotron.py
@@ -0,0 +1,58 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+graph_config = {
+ "llm": {
+ "api_key": os.getenv("NEMOTRON_APIKEY"),
+ "model": "nvidia/meta/llama3-70b-instruct",
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/oneapi/code_generator_graph_oneapi.py b/examples/oneapi/code_generator_graph_oneapi.py
new file mode 100644
index 00000000..0bbb3ba2
--- /dev/null
+++ b/examples/oneapi/code_generator_graph_oneapi.py
@@ -0,0 +1,61 @@
+"""
+Basic example of scraping pipeline using Code Generator with schema
+"""
+
+import os, json
+from typing import List
+from dotenv import load_dotenv
+from langchain_core.pydantic_v1 import BaseModel, Field
+from scrapegraphai.graphs import CodeGeneratorGraph
+
+load_dotenv()
+
+# ************************************************
+# Define the output schema for the graph
+# ************************************************
+
+class Project(BaseModel):
+ title: str = Field(description="The title of the project")
+ description: str = Field(description="The description of the project")
+
+class Projects(BaseModel):
+ projects: List[Project]
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+openai_key = os.getenv("OPENAI_APIKEY")
+
+graph_config = {
+ "llm": {
+ "api_key": "***************************",
+ "model": "oneapi/qwen-turbo",
+ "base_url": "http://127.0.0.1:3000/v1", # 设置 OneAPI URL
+ },
+ "verbose": True,
+ "headless": False,
+ "reduction": 2,
+ "max_iterations": {
+ "overall": 10,
+ "syntax": 3,
+ "execution": 3,
+ "validation": 3,
+ "semantic": 3
+ },
+ "output_file_name": "extracted_data.py"
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+code_generator_graph = CodeGeneratorGraph(
+ prompt="List me all the projects with their description",
+ source="https://perinim.github.io/projects/",
+ schema=Projects,
+ config=graph_config
+)
+
+result = code_generator_graph.run()
+print(result)
\ No newline at end of file
diff --git a/examples/code_generation/simple_with_schema.py b/examples/openai/code_generator_graph_openai.py
similarity index 97%
rename from examples/code_generation/simple_with_schema.py
rename to examples/openai/code_generator_graph_openai.py
index 544c1724..21a4a02f 100644
--- a/examples/code_generation/simple_with_schema.py
+++ b/examples/openai/code_generator_graph_openai.py
@@ -30,7 +30,7 @@ openai_key = os.getenv("OPENAI_APIKEY")
graph_config = {
"llm": {
"api_key":openai_key,
- "model": "openai/gpt-4o-mini",\
+ "model": "openai/gpt-4o-mini",
},
"verbose": True,
"headless": False,