Skip to content

Commit

Permalink
fix: update to pydantic documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
VinciGit00 committed Sep 25, 2024
1 parent d55f6be commit 76ce257
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/anthropic/code_generator_graph_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/azure/code_generator_graph_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/bedrock/code_generator_graph_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/deepseek/code_generator_graph_deepseek.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/ernie/code_generator_graph_ernie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/fireworks/code_generator_graph_fireworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/google_genai/code_generator_graph_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/google_vertexai/code_generator_graph_vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/groq/code_generator_graph_groq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph
from langchain_community.llms import HuggingFaceEndpoint
from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
Expand Down
2 changes: 1 addition & 1 deletion examples/local_models/code_generator_graph_ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/mistral/code_generator_graph_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/moonshot/code_generator_graph_moonshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from langchain_community.chat_models.moonshot import MoonshotChat
from scrapegraphai.graphs import CodeGeneratorGraph

Expand Down
2 changes: 1 addition & 1 deletion examples/nemotron/code_generator_graph_nemotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/oneapi/code_generator_graph_oneapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
2 changes: 1 addition & 1 deletion examples/openai/code_generator_graph_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, json
from typing import List
from dotenv import load_dotenv
from langchain_core.pydantic_v1 import BaseModel, Field
from pydantic import BaseModel, Field
from scrapegraphai.graphs import CodeGeneratorGraph

load_dotenv()
Expand Down
28 changes: 28 additions & 0 deletions extracted_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def extract_data(html: str) -> dict:
from bs4 import BeautifulSoup

# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(html, 'html.parser')

# Initialize an empty list to hold project data
projects = []

# Find all project entries in the HTML
project_entries = soup.find_all('div', class_='grid-item')

# Iterate over each project entry to extract title and description
for entry in project_entries:
# Extract the title from the card-title class
title = entry.find('h4', class_='card-title').get_text(strip=True)

# Extract the description from the card-text class
description = entry.find('p', class_='card-text').get_text(strip=True)

# Append the extracted data as a dictionary to the projects list
projects.append({
'title': title,
'description': description
})

# Return the structured data as a dictionary matching the desired JSON schema
return {'projects': projects}
1 change: 0 additions & 1 deletion scrapegraphai/nodes/fetch_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,3 @@ def handle_web_source(self, state, source):
state["original_html"] = document
state.update({self.output[0]: compressed_document,})
return state

8 changes: 4 additions & 4 deletions scrapegraphai/utils/schema_trasform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def transform_schema(pydantic_schema):
Returns:
dict: The transformed JSON schema.
"""

def process_properties(properties):
result = {}
for key, value in properties.items():
if 'type' in value:
if value['type'] == 'array':
if '$ref' in value['items']:
ref_key = value['items']['$ref'].split('/')[-1]
result[key] = [process_properties(pydantic_schema['definitions'][ref_key]['properties'])]
result[key] = [process_properties(pydantic_schema['$defs'][ref_key]['properties'])]
else:
result[key] = [value['items']['type']]
else:
Expand All @@ -30,7 +30,7 @@ def process_properties(properties):
}
elif '$ref' in value:
ref_key = value['$ref'].split('/')[-1]
result[key] = process_properties(pydantic_schema['definitions'][ref_key]['properties'])
result[key] = process_properties(pydantic_schema['$defs'][ref_key]['properties'])
return result

return process_properties(pydantic_schema['properties'])
return process_properties(pydantic_schema['properties'])

0 comments on commit 76ce257

Please sign in to comment.