Nick: llm extract support on node sdk

This commit is contained in:
Nicolas
2024-08-30 13:43:19 -03:00
parent 45e33563eb
commit a2881e9288
4 changed files with 69 additions and 24 deletions
+15 -1
View File
@@ -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) {
+15 -1
View File
@@ -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) {