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)