getAiFunction function

Last updated: 2026-03-04T23:21:38.398Z

Metrics

LOC: 30 Complexity: 5 Params: 2

Signature

getAiFunction( settings: Settings, ): : Promise<((field: FormField) => Promise<string>) | undefined>

Source Code

async function getAiFunction(
  settings: Settings,
): Promise<((field: FormField) => Promise<string>) | undefined> {
  log.debug(
    `useChromeAI=${settings.useChromeAI} | defaultStrategy=${settings.defaultStrategy} | forceAIFirst=${settings.forceAIFirst}`,
  );

  if (settings.useChromeAI) {
    const available = await isChromeAiAvailable();
    log.debug(`Chrome AI disponível: ${available}`);
    if (available) {
      log.debug("Usando Chrome AI (Gemini Nano).");
      return chromeAiGenerate;
    }
  }

  // Fallback to TF.js when strategy is "ai" or "tensorflow"
  if (
    settings.defaultStrategy === "tensorflow" ||
    settings.defaultStrategy === "ai"
  ) {
    log.debug("Usando TensorFlow.js como fallback de AI.");
    return async (field: FormField) => await generateWithTensorFlow(field);
  }

  log.warn(
    "Nenhuma função de AI configurada. Será usado apenas o gerador padrão.",
  );
  return undefined;
}

No outgoing dependencies.

Impact (Incoming)

graph LR getAiFunction["getAiFunction"] doFillAllFields["doFillAllFields"] fillSingleField["fillSingleField"] doFillAllFields -->|calls| getAiFunction fillSingleField -->|calls| getAiFunction style getAiFunction fill:#dbeafe,stroke:#2563eb,stroke-width:2px click getAiFunction "da66edfde6d3db9f.html" click doFillAllFields "23fe5c1a0125e335.html" click fillSingleField "e1740bceca6b34c2.html"
SourceType
doFillAllFields calls
fillSingleField calls