GenerationOptions
Per-request controls. Leave any field as null / nil to fall back to the manifest defaults.
- Swift (iOS / macOS)
- Kotlin (all platforms)
GenerationOptions is a Kotlin data class bridged into Swift. Kotlin parameter defaults don’t survive the ObjC bridge, so the canonical Swift idiom is the parameterless init plus chained .with(...) builders:Leap.load(...) flows), GenerationOptionsCompat additionally exposes setResponseFormat(jsonSchema: String).- Sampling fields —
temperature,topP,minP,topK, andrepetitionPenalty. Use the model bundle’s recommended values; arbitrary defaults from generic tutorials usually underperform. rngSeed— deterministic sampling seed for tests and reproducible runs.maxTokens— maximum completion tokens to generate. Prompt tokens do not count toward this cap.jsonSchemaConstraint— JSON Schema string for constrained generation. Use the higher-level helpers — Swiftoptions.with(jsonSchema: T.jsonSchema())/ KotlinsetResponseFormatType<T>()— instead of writing the schema by hand.injectSchemaIntoPrompt— whentrue(default), the schema is also appended to the system message for semantic guidance. Setfalseto use only the structural constraint.functionCallParser—LFMFunctionCallParser(default),HermesFunctionCallParser(), ornull/nilto disable parsing and surface raw tool-call text inChunks.enableThinking/inlineThinkingTags— reasoning-mode controls for models that emit<think>content.extras— backend-specific JSON payload.
Constrained generation utilities
- Swift (iOS / macOS)
- Kotlin (all platforms)
JSONSchemaGenerator.getJSONSchema(for:) is non-throwing — it forwards to the jsonSchema() method that the @Generatable macro adds to the type, so the schema is produced at compile time. Useful when embedding the schema in the prompt itself, or when you want to debug the schema the model is being constrained against.See Constrained Generation for the full @Generatable / @Guide macro reference.Function-calling type reference
The full surface is documented in Function Calling; the type signatures here are the at-a-glance reference.- Swift (iOS / macOS)
- Kotlin (all platforms)
StringType, NumberType, etc.) carry per-type metadata like enumValues for restricting valid inputs and description for prompt-time hints (used when the type is nested inside an array or object).Parsers
Two parser implementations ship with the SDK on every platform:LFMFunctionCallParser— default. Handles Liquid Foundation Model (LFM2) Pythonic-style control tokens (<|tool_call_start|>/<|tool_call_end|>).HermesFunctionCallParser— Qwen3 and other models using the Hermes function-calling format.
LeapFunctionCallParser (Kotlin abstract class, bridged to Swift as a class with the same name) to add support for a new format.
Prompt token budgeting
getPromptTokensSize(messages:, addBosToken:) is declared directly on ModelRunner — no cast required. Useful when you need to estimate context usage before sending a long request.
- Swift (iOS / macOS)
- Kotlin (all platforms)