respond(schema:includeSchemaInPrompt:options:prompt:)
Produces a generated content type as a response to a prompt and schema.
Declaration
@discardableResult nonisolated(nonsending) final func respond(schema: GenerationSchema, includeSchemaInPrompt: Bool = true, options: GenerationOptions = GenerationOptions(), @PromptBuilder prompt: () throws -> Prompt) async throws -> LanguageModelSession.Response<GeneratedContent>Parameters
- schema:
A schema to guide the output with.
- includeSchemaInPrompt:
Inject the schema into the prompt to bias the model.
- options:
Options that control how tokens are sampled from the distribution the model produces.
- prompt:
A prompt for the model to respond to.
Return Value
GeneratedContent containing the fields and values defined in the schema.
Discussion
Consider using the default value of true for includeSchemaInPrompt. The exception to the rule is when the model has knowledge about the expected response format, either because it has been trained on it, or because it has seen exhaustive examples during this session.