mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-14 03:55:55 +08:00
fixed nested data inside extract
This commit is contained in:
parent
53e0cb6b19
commit
943bbae88d
@ -211,7 +211,9 @@ export async function extractController(
|
|||||||
prompt: req.body.prompt,
|
prompt: req.body.prompt,
|
||||||
schema: req.body.schema,
|
schema: req.body.schema,
|
||||||
},
|
},
|
||||||
docs.map(x => buildDocument(x)).join('\n')
|
docs.map(x => buildDocument(x)).join('\n'),
|
||||||
|
undefined,
|
||||||
|
true // isExtractEndpoint
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: change this later
|
// TODO: change this later
|
||||||
|
@ -58,7 +58,7 @@ function normalizeSchema(x: any): any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generateOpenAICompletions(logger: Logger, options: ExtractOptions, markdown?: string, previousWarning?: string): Promise<{ extract: any, numTokens: number, warning: string | undefined }> {
|
export async function generateOpenAICompletions(logger: Logger, options: ExtractOptions, markdown?: string, previousWarning?: string, isExtractEndpoint?: boolean): Promise<{ extract: any, numTokens: number, warning: string | undefined }> {
|
||||||
let extract: any;
|
let extract: any;
|
||||||
let warning: string | undefined;
|
let warning: string | undefined;
|
||||||
|
|
||||||
@ -158,7 +158,12 @@ export async function generateOpenAICompletions(logger: Logger, options: Extract
|
|||||||
|
|
||||||
if (extract === null && jsonCompletion.choices[0].message.content !== null) {
|
if (extract === null && jsonCompletion.choices[0].message.content !== null) {
|
||||||
try {
|
try {
|
||||||
|
if (!isExtractEndpoint) {
|
||||||
extract = JSON.parse(jsonCompletion.choices[0].message.content);
|
extract = JSON.parse(jsonCompletion.choices[0].message.content);
|
||||||
|
} else {
|
||||||
|
const extractData = JSON.parse(jsonCompletion.choices[0].message.content);
|
||||||
|
extract = extractData.data.extract;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Failed to parse returned JSON, no schema specified.", { error: e });
|
logger.error("Failed to parse returned JSON, no schema specified.", { error: e });
|
||||||
throw new LLMRefusalError("Failed to parse returned JSON. Please specify a schema in the extract object.");
|
throw new LLMRefusalError("Failed to parse returned JSON. Please specify a schema in the extract object.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user