# utils.chat_templates

`utils.chat_templates`

This module provides functionality for selecting chat templates based on user choices. These templates are used for formatting messages in a conversation.

## Functions

Name | Description
--- | ---
get_chat_template | Finds the correct chat_template based on the user’s choice, jinja_template, and tokenizer.
register_chat_template | Registers chat templates.

### get_chat_template

    utils.chat_templates.get_chat_template(
        user_choice,
        jinja_template=None,
        tokenizer=None,
    )

Finds the correct chat_template based on the user’s choice, jinja_template, and tokenizer.

#### Parameters

Name | Type | Description | Default
--- | --- | --- | ---
user_choice | str | The user’s choice of template. | required
jinja_template | Optional[str] | The jinja template string. Defaults to None. | `None`
tokenizer | Optional[PreTrainedTokenizerBase] | The tokenizer. Defaults to None. | `None`

#### Returns

Name | Type | Description
--- | --- | ---
str | str | The chosen template string.

#### Raises

Name | Type | Description
--- | --- | ---
| ValueError | If the user_choice is not found in the templates.

### register_chat_template

    utils.chat_templates.register_chat_template(template_name, chat_template)

Registers chat templates.

#### Parameters

Name | Type | Description | Default
--- | --- | --- | ---
template_name | str | The name of the template. | required
chat_template | str | The template string. | required