This commit is contained in:
Gergő Móricz 2025-04-15 23:54:56 -07:00
parent 2193bee133
commit 2245650bc3
2 changed files with 5 additions and 4 deletions

View File

@ -8,14 +8,15 @@ import {
buildAnalyzeSchemaPrompt, buildAnalyzeSchemaPrompt,
buildAnalyzeSchemaUserPrompt, buildAnalyzeSchemaUserPrompt,
} from "../build-prompts"; } from "../build-prompts";
import { logger } from "../../../lib/logger";
import { jsonSchema } from "ai"; import { jsonSchema } from "ai";
import { getModel } from "../../../lib/generic-ai"; import { getModel } from "../../../lib/generic-ai";
import { Logger } from "winston";
export async function analyzeSchemaAndPrompt( export async function analyzeSchemaAndPrompt(
urls: string[], urls: string[],
schema: any, schema: any,
prompt: string, prompt: string,
logger: Logger,
): Promise<{ ): Promise<{
isMultiEntity: boolean; isMultiEntity: boolean;
multiEntityKeys: string[]; multiEntityKeys: string[];
@ -26,7 +27,7 @@ export async function analyzeSchemaAndPrompt(
}> { }> {
let cost = 0; let cost = 0;
if (!schema) { if (!schema) {
const genRes = await generateSchemaFromPrompt(prompt); const genRes = await generateSchemaFromPrompt(prompt, logger);
schema = genRes.extract; schema = genRes.extract;
cost = genRes.cost; cost = genRes.cost;
} }

View File

@ -178,7 +178,7 @@ export async function performExtraction(
let reqSchema = request.schema; let reqSchema = request.schema;
if (!reqSchema && request.prompt) { if (!reqSchema && request.prompt) {
const schemaGenRes = await generateSchemaFromPrompt(request.prompt); const schemaGenRes = await generateSchemaFromPrompt(request.prompt, logger);
reqSchema = schemaGenRes.extract; reqSchema = schemaGenRes.extract;
costTracking.otherCallCount++; costTracking.otherCallCount++;
costTracking.otherCost += schemaGenRes.cost; costTracking.otherCost += schemaGenRes.cost;
@ -214,7 +214,7 @@ export async function performExtraction(
keyIndicators, keyIndicators,
tokenUsage: schemaAnalysisTokenUsage, tokenUsage: schemaAnalysisTokenUsage,
cost: schemaAnalysisCost, cost: schemaAnalysisCost,
} = await analyzeSchemaAndPrompt(urls, reqSchema, request.prompt ?? ""); } = await analyzeSchemaAndPrompt(urls, reqSchema, request.prompt ?? "", logger);
logger.debug("Analyzed schema.", { logger.debug("Analyzed schema.", {
isMultiEntity, isMultiEntity,