generate static method

Future<StructuredOutputResult> generate(
  1. String prompt, {
  2. required String jsonSchema,
  3. int maxTokens = 512,
  4. double temperature = 0.0,
})

Generate text constrained by a JSON schema string jsonSchema using the lifecycle-owned LLM. Commons owns the full pipeline (prepare prompt → run LLM → strip thinking tags → extract JSON → validate). maxTokens and temperature are accepted for cross-SDK API parity; commons currently uses default generation parameters.

Implementation

static Future<StructuredOutputResult> generate(
  String prompt, {
  required String jsonSchema,
  int maxTokens = 512,
  double temperature = 0.0,
}) async {
  if (!DartBridge.isInitialized) throw SDKException.notInitialized();
  if (RunAnywhereLLM.shared.currentModelId == null) {
    throw SDKException.componentNotReady(
      'LLM model not loaded. Call RunAnywhere.llm.load(modelId) first.',
    );
  }

  final options = StructuredOutputOptions(
    schema: JSONSchema(rawJson: jsonSchema),
    jsonSchema: jsonSchema,
    includeSchemaInPrompt: true,
  );
  final request = DartBridgeStructuredOutput.shared.makeGenerateRequest(
    prompt: prompt,
    options: options,
  );
  return generateRequest(request);
}