Nick: fixed extract schema
This commit is contained in:
@@ -13,7 +13,7 @@ import os
|
|||||||
|
|
||||||
from .firecrawl import FirecrawlApp # noqa
|
from .firecrawl import FirecrawlApp # noqa
|
||||||
|
|
||||||
__version__ = "1.7.0"
|
__version__ = "1.7.1"
|
||||||
|
|
||||||
# Define the logger for the Firecrawl project
|
# Define the logger for the Firecrawl project
|
||||||
logger: logging.Logger = logging.getLogger("firecrawl")
|
logger: logging.Logger = logging.getLogger("firecrawl")
|
||||||
|
|||||||
@@ -472,20 +472,24 @@ class FirecrawlApp:
|
|||||||
if not params or not params.get('prompt'):
|
if not params or not params.get('prompt'):
|
||||||
raise ValueError("Prompt is required")
|
raise ValueError("Prompt is required")
|
||||||
|
|
||||||
if not params.get('schema'):
|
schema = params.get('schema')
|
||||||
raise ValueError("Schema is required for extraction")
|
if schema:
|
||||||
|
if hasattr(schema, 'model_json_schema'):
|
||||||
|
# Convert Pydantic model to JSON schema
|
||||||
|
schema = schema.model_json_schema()
|
||||||
|
# Otherwise assume it's already a JSON schema dict
|
||||||
|
|
||||||
jsonData = {'urls': urls, **params}
|
jsonData = {'urls': urls, **params}
|
||||||
jsonSchema = params['schema'].schema() if hasattr(params['schema'], 'schema') else None
|
request_data = {
|
||||||
|
**jsonData,
|
||||||
|
'allowExternalLinks': params.get('allow_external_links', False),
|
||||||
|
'schema': schema
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = self._post_request(
|
response = self._post_request(
|
||||||
f'{self.api_url}/v1/extract',
|
f'{self.api_url}/v1/extract',
|
||||||
{
|
request_data,
|
||||||
**jsonData,
|
|
||||||
'allowExternalLinks': params.get('allow_external_links', False),
|
|
||||||
'schema': jsonSchema
|
|
||||||
},
|
|
||||||
headers
|
headers
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
|||||||
Reference in New Issue
Block a user