# TemplateGenerativeModel


```
@PublicPreviewAPI
class TemplateGenerativeModel
```

<br />

*** ** * ** ***

Represents a multimodal model (like Gemini), capable of generating content based on various templated input types.

## Summary

| ### Public functions |
|---|---|
| `suspend https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/GenerateContentResponse` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateGenerativeModel#generateContent(kotlin.String,kotlin.collections.Map)(templateId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, inputs: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>)` Generates content from a prompt template and inputs. |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/GenerateContentResponse>` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateGenerativeModel#generateContentStream(kotlin.String,kotlin.collections.Map)(templateId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, inputs: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>)` Generates content as a stream from a prompt template and inputs. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateChat` | `@https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/PublicPreviewAPI https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateGenerativeModel#startChat(kotlin.String,kotlin.collections.Map,kotlin.collections.List)( templateId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, inputs: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>, history: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/Content> )` Creates a `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateChat` instance using this model with the optionally provided history. |

## Public functions

### generateContent

```
suspend fun generateContent(templateId: String, inputs: Map<String, Any>): GenerateContentResponse
```

Generates content from a prompt template and inputs.

| Parameters |
|---|---|
| `templateId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The ID of the prompt template to use. |
| `inputs: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>` | A map of variables to substitute into the template. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/GenerateContentResponse` | The content generated by the model. |

| Throws |
|---|---|
| `com.google.firebase.ai.type.FirebaseAIException: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/FirebaseAIException` | if the request failed. |

| See also |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/FirebaseAIException` | for types of errors. |

### generateContentStream

```
fun generateContentStream(templateId: String, inputs: Map<String, Any>): Flow<GenerateContentResponse>
```

Generates content as a stream from a prompt template and inputs.

| Parameters |
|---|---|
| `templateId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The ID of the prompt template to use. |
| `inputs: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>` | A map of variables to substitute into the template. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/GenerateContentResponse>` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` which will emit responses as they are returned by the model. |

| Throws |
|---|---|
| `com.google.firebase.ai.type.FirebaseAIException: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/FirebaseAIException` | if the request failed. |

| See also |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/FirebaseAIException` | for types of errors. |

### startChat

```
@PublicPreviewAPI
fun startChat(
    templateId: String,
    inputs: Map<String, Any>,
    history: List<Content> = emptyList()
): TemplateChat
```

Creates a `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateChat` instance using this model with the optionally provided history.

| Parameters |
|---|---|
| `templateId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The ID of the prompt template to use. |
| `inputs: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html>` | A map of variables to substitute into the template for the session. |
| `history: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/Content> = emptyList()` | Prior history in the conversation. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateChat` | The initialized `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/TemplateChat` instance. |