mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 17:49:02 +08:00
fix(llmExtract): remove unsupported JSON schema properties (#1335)
This commit is contained in:
parent
387dd3aa38
commit
c3ebfafba7
@ -29,6 +29,28 @@ describe("Extract tests", () => {
|
|||||||
expect(typeof res.data.is_open_source).toBe("boolean");
|
expect(typeof res.data.is_open_source).toBe("boolean");
|
||||||
expect(res.data.is_open_source).toBe(true);
|
expect(res.data.is_open_source).toBe(true);
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|
||||||
|
it.concurrent("works with unsupported JSON schema parameters", async () => {
|
||||||
|
const res = await extract({
|
||||||
|
urls: ["https://firecrawl.dev"],
|
||||||
|
schema: {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"company_name": {
|
||||||
|
"type": "string",
|
||||||
|
"pattern": "^[a-zA-Z0-9]+$"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"company_name"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
origin: "api-sdk",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.data).toHaveProperty("company_name");
|
||||||
|
expect(typeof res.data.company_name).toBe("string")
|
||||||
|
}, 60000);
|
||||||
} else {
|
} else {
|
||||||
it.concurrent("dummy test", () => {
|
it.concurrent("dummy test", () => {
|
||||||
expect(true).toBe(true);
|
expect(true).toBe(true);
|
||||||
|
@ -365,7 +365,37 @@ export async function performLLMExtract(
|
|||||||
export function removeDefaultProperty(schema: any): any {
|
export function removeDefaultProperty(schema: any): any {
|
||||||
if (typeof schema !== "object" || schema === null) return schema;
|
if (typeof schema !== "object" || schema === null) return schema;
|
||||||
|
|
||||||
const { default: _, ...rest } = schema;
|
const rest = { ...schema };
|
||||||
|
|
||||||
|
// unsupported global keys
|
||||||
|
delete rest.default;
|
||||||
|
|
||||||
|
// unsupported object keys
|
||||||
|
delete rest.patternProperties;
|
||||||
|
delete rest.unevaluatedProperties;
|
||||||
|
delete rest.propertyNames;
|
||||||
|
delete rest.minProperties;
|
||||||
|
delete rest.maxProperties;
|
||||||
|
|
||||||
|
// unsupported string keys
|
||||||
|
delete rest.minLength;
|
||||||
|
delete rest.maxLength;
|
||||||
|
delete rest.pattern;
|
||||||
|
delete rest.format;
|
||||||
|
|
||||||
|
// unsupported number keys
|
||||||
|
delete rest.minimum;
|
||||||
|
delete rest.maximum;
|
||||||
|
delete rest.multipleOf;
|
||||||
|
|
||||||
|
// unsupported array keys
|
||||||
|
delete rest.unevaluatedItems;
|
||||||
|
delete rest.contains;
|
||||||
|
delete rest.minContains;
|
||||||
|
delete rest.maxContains;
|
||||||
|
delete rest.minItems;
|
||||||
|
delete rest.maxItems;
|
||||||
|
delete rest.uniqueItems;
|
||||||
|
|
||||||
for (const key in rest) {
|
for (const key in rest) {
|
||||||
if (Array.isArray(rest[key])) {
|
if (Array.isArray(rest[key])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user