Fluentic<R> constructor

Fluentic<R>({
  1. required String promptTemplate,
  2. FluenticConfig? config,
  3. LlmApiClient? llmClient,
})

Implementation

Fluentic({
  required String promptTemplate,
  FluenticConfig? config,
  LlmApiClient? llmClient,
}) : _basePromptTemplate = promptTemplate,
     _llmClient =
         llmClient ??
         OpenAiApiClient(config: config ?? FluenticConfig.global),
     _adapterForR =
         isPlainFluenticType(R) // <<< CHECK PLAIN TYPE
             ? null // Plain types don't have/need adapters from our custom registry
             : fluenticTypeAdapters[R] as FluenticTypeAdapter<R>? {
  _orderedPlaceholdersInTemplate = _extractPlaceholders(_basePromptTemplate);

  dev.log(
    "DEBUG: Fluentic<$R> constructor. IsPlainType: ${isPlainFluenticType(R)}",
  );

  if (_adapterForR != null) {
    // Adapter found for a custom type
    dev.log(
      "DEBUG: Fluentic<$R>: Custom type adapter FOUND. Example: ${_adapterForR!.exampleInstance.runtimeType}",
    );
  } else if (!isPlainFluenticType(R)) {
    // Custom type BUT adapter NOT found
    dev.log(
      "CRITICAL WARNING: Fluentic<$R>: No adapter found for CUSTOM type '$R'. "
      "Ensure 'registerFluenticModel<$R>(...)' was called for this type.",
    );
    // throw StateError("Fluentic: No adapter registered for custom type '$R'.");
  } else {
    // Plain type, no adapter needed/expected from our registry
    dev.log("DEBUG: Fluentic<$R>: Plain type. No custom adapter needed.");
  }
}