Nick: llm extract support on node sdk
This commit is contained in:
@@ -35,7 +35,7 @@ class FirecrawlApp {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
};
|
||||
let jsonData = { url, ...params };
|
||||
if (jsonData?.extractorOptions?.extractionSchema) {
|
||||
if (this.version === 'v0' && jsonData?.extractorOptions?.extractionSchema) {
|
||||
let schema = jsonData.extractorOptions.extractionSchema;
|
||||
// Check if schema is an instance of ZodSchema to correctly identify Zod schemas
|
||||
if (schema instanceof zod_1.z.ZodSchema) {
|
||||
@@ -50,6 +50,20 @@ class FirecrawlApp {
|
||||
},
|
||||
};
|
||||
}
|
||||
else if (this.version === 'v1' && jsonData?.extract?.schema) {
|
||||
let schema = jsonData.extract.schema;
|
||||
// Check if schema is an instance of ZodSchema to correctly identify Zod schemas
|
||||
if (schema instanceof zod_1.z.ZodSchema) {
|
||||
schema = (0, zod_to_json_schema_1.zodToJsonSchema)(schema);
|
||||
}
|
||||
jsonData = {
|
||||
...jsonData,
|
||||
extract: {
|
||||
...jsonData.extract,
|
||||
schema: schema,
|
||||
},
|
||||
};
|
||||
}
|
||||
try {
|
||||
const response = await axios_1.default.post(this.apiUrl + `/${this.version}/scrape`, jsonData, { headers });
|
||||
if (response.status === 200) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export default class FirecrawlApp {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
};
|
||||
let jsonData = { url, ...params };
|
||||
if (jsonData?.extractorOptions?.extractionSchema) {
|
||||
if (this.version === 'v0' && jsonData?.extractorOptions?.extractionSchema) {
|
||||
let schema = jsonData.extractorOptions.extractionSchema;
|
||||
// Check if schema is an instance of ZodSchema to correctly identify Zod schemas
|
||||
if (schema instanceof z.ZodSchema) {
|
||||
@@ -45,6 +45,20 @@ export default class FirecrawlApp {
|
||||
},
|
||||
};
|
||||
}
|
||||
else if (this.version === 'v1' && jsonData?.extract?.schema) {
|
||||
let schema = jsonData.extract.schema;
|
||||
// Check if schema is an instance of ZodSchema to correctly identify Zod schemas
|
||||
if (schema instanceof z.ZodSchema) {
|
||||
schema = zodToJsonSchema(schema);
|
||||
}
|
||||
jsonData = {
|
||||
...jsonData,
|
||||
extract: {
|
||||
...jsonData.extract,
|
||||
schema: schema,
|
||||
},
|
||||
};
|
||||
}
|
||||
try {
|
||||
const response = await axios.post(this.apiUrl + `/${this.version}/scrape`, jsonData, { headers });
|
||||
if (response.status === 200) {
|
||||
|
||||
Reference in New Issue
Block a user