generateObject

actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: Content, vararg prompts: Content): GenerateObjectResponse<T>(source)

Generates an object from the input Content given to the model as a prompt.

Note for Structured Output:

  • For on-device and hybrid inference (ONLY_ON_DEVICE, PREFER_ON_DEVICE, and PREFER_IN_CLOUD): Requires using the @Generable annotation on a data class. Manual schemas are not supported.

  • For cloud-only inference (ONLY_IN_CLOUD): Supports both @Generable annotations (recommended) and manual schemas.

Return

The content generated by the model.

Parameters

jsonSchema

A schema for the output

prompt

The input(s) given to the model as a prompt.

See also

for types of errors.

Throws

if the request failed.


actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: String): GenerateObjectResponse<T>(source)

Generates an object from the text input given to the model as a prompt.

Note for Structured Output:

  • For on-device and hybrid inference (ONLY_ON_DEVICE, PREFER_ON_DEVICE, and PREFER_IN_CLOUD): Requires using the @Generable annotation on a data class. Manual schemas are not supported.

  • For cloud-only inference (ONLY_IN_CLOUD): Supports both @Generable annotations (recommended) and manual schemas.

Return

The content generated by the model.

Parameters

jsonSchema

A schema for the output

prompt

The text to be send to the model as a prompt.

See also

for types of errors.

Throws

if the request failed.

expect suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: Content, vararg prompts: Content): GenerateObjectResponse<T>(source)

Generates an object from the input Content given to the model as a prompt.

Note for Structured Output:

  • For on-device and hybrid inference (ONLY_ON_DEVICE, PREFER_ON_DEVICE, and PREFER_IN_CLOUD): Requires using the @Generable annotation on a data class. Manual schemas are not supported.

  • For cloud-only inference (ONLY_IN_CLOUD): Supports both @Generable annotations (recommended) and manual schemas.

Return

The content generated by the model.

Parameters

jsonSchema

A schema for the output

prompt

The input(s) given to the model as a prompt.

See also

for types of errors.

Throws

if the request failed.


expect suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: String): GenerateObjectResponse<T>(source)

Generates an object from the text input given to the model as a prompt.

Note for Structured Output:

  • For on-device and hybrid inference (ONLY_ON_DEVICE, PREFER_ON_DEVICE, and PREFER_IN_CLOUD): Requires using the @Generable annotation on a data class. Manual schemas are not supported.

  • For cloud-only inference (ONLY_IN_CLOUD): Supports both @Generable annotations (recommended) and manual schemas.

Return

The content generated by the model.

Parameters

jsonSchema

A schema for the output

prompt

The text to be send to the model as a prompt.

See also

for types of errors.

Throws

if the request failed.

actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: Content, vararg prompts: Content): GenerateObjectResponse<T>(source)

Generates an object from the input Content given to the model as a prompt.

Note for Structured Output:

  • For on-device and hybrid inference (ONLY_ON_DEVICE, PREFER_ON_DEVICE, and PREFER_IN_CLOUD): Requires using the @Generable annotation on a data class. Manual schemas are not supported.

  • For cloud-only inference (ONLY_IN_CLOUD): Supports both @Generable annotations (recommended) and manual schemas.

Return

The content generated by the model.

Parameters

jsonSchema

A schema for the output

prompt

The input(s) given to the model as a prompt.

See also

for types of errors.

Throws

if the request failed.


actual suspend fun <T : Any> generateObject(jsonSchema: JsonSchema<T>, prompt: String): GenerateObjectResponse<T>(source)

Generates an object from the text input given to the model as a prompt.

Note for Structured Output:

  • For on-device and hybrid inference (ONLY_ON_DEVICE, PREFER_ON_DEVICE, and PREFER_IN_CLOUD): Requires using the @Generable annotation on a data class. Manual schemas are not supported.

  • For cloud-only inference (ONLY_IN_CLOUD): Supports both @Generable annotations (recommended) and manual schemas.

Return

The content generated by the model.

Parameters

jsonSchema

A schema for the output

prompt

The text to be send to the model as a prompt.

See also

for types of errors.

Throws

if the request failed.