mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 20:59:00 +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,
|
||||
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
|
||||
|
@ -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 warning: string | undefined;
|
||||
|
||||
@ -158,7 +158,12 @@ export async function generateOpenAICompletions(logger: Logger, options: Extract
|
||||
|
||||
if (extract === null && jsonCompletion.choices[0].message.content !== null) {
|
||||
try {
|
||||
extract = JSON.parse(jsonCompletion.choices[0].message.content);
|
||||
if (!isExtractEndpoint) {
|
||||
extract = JSON.parse(jsonCompletion.choices[0].message.content);
|
||||
} else {
|
||||
const extractData = JSON.parse(jsonCompletion.choices[0].message.content);
|
||||
extract = extractData.data.extract;
|
||||
}
|
||||
} catch (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.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user