> For the complete documentation index, see [llms.txt](https://utca.knowledgator.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://utca.knowledgator.com/tasks/transformerschat.md).

# TransformersChat

Basic chat task

Subclass of [**Task**](/tasks/task.md)**.**&#x20;

## Module: [implementation](/framework-structure.md#implementation).tasks

## Default predictor

This task uses [**TransformersModel**](/predictors/transformers-predictors.md#transformersmodel) by default with this configuration:

{% code overflow="wrap" fullWidth="false" %}

```python
TransformersPipeline(
    TransformersPipelineConfig(
        task="text-generation", 
        model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
        kwargs={
            "max_new_tokens": 256, 
            "do_sample": True, 
            "temperature": 0.3, 
            "top_k": 50, 
            "top_p": 0.95,
        }
    ),
    input_class=TransformersBasicInput,
    output_class=TransformersBasicOutput
)
```

{% endcode %}

#### **See:**

* [**TransformersPipeline**](/predictors/transformers-predictors.md#transformerspipeline)&#x20;
* [**TransformersPipelineConfig**](/predictors/transformers-predictors.md#transformerspipelineconfig)
* [**TransformersBasicInput**](/predictors/transformers-schemas.md#transformersbasicinput)
* [**TransformersBasicOutput**](/predictors/transformers-schemas.md#transformersbasicoutput)

## Methods and properties

Main methods and properties

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**predictor**</mark>**&#x20;(**[**Predictor**](/predictors/predictor.md)**\[Any, Any], optional):** Predictor that will be used in task. If equals to None, [**default predictor**](#default-predictor) will be used. Defaults to None.
* <mark style="color:orange;">**messages**</mark>**&#x20;(Optional\[str], optional):** Key to use to access memory for messages. If equals to None, a unique key will be generated. Defaults to None.

{% hint style="warning" %}
***Note***: This parameter will function as expected only when using the default preprocessor and postprocessor.
{% endhint %}

* <mark style="color:orange;">**preprocess**</mark>**&#x20;(Optional\[**[**Component**](/core/component.md)**], optional):** Component executed before predictor. If equals to None, default component will be used. Defaults to None.\
  \
  Default component: \
  [**ChatPreprocessor**](#chatpreprocessor) **|** [**GetMemory**](/core/memory-management.md#getmemory) **|** [**ChatAddContext**](/tasks/chat-tasks-utilities.md#chataddcontext) **|** [**SetMemory**](/core/memory-management.md#setmemory) **|** [**RenameAttribute**](/base-actions/renameattribute.md)
* <mark style="color:orange;">**postprocess**</mark>**&#x20;(Optional\[**[**Component**](/core/component.md)**], optional):** Component executed after predictor. If equals to None, default component will be used. Defaults to None.\
  \
  Default component: \
  [**ChatPostprocessor**](#chatpostprocessor) **|** [**GetMemory** ](/core/memory-management.md#getmemory)**|** [**ChatUpdateContext**](/tasks/chat-tasks-utilities.md#chatupdatecontext) **|** [**SetMemory**](/core/memory-management.md#setmemory)
* <mark style="color:orange;">**input\_class**</mark>**&#x20;(Type\[**[**Input**](/core/schemas.md#input)**], optional):** Class for input validation. Defaults to [**ChatInput**](/tasks/chat-tasks-utilities.md#chatinput)**.**
* <mark style="color:orange;">**output\_class**</mark>**&#x20;(Type\[**[**NEROutputType**](/tasks/task.md#neroutputtype)**], optional):** Class for output validation. Defaults to [**ChatOutput**](/tasks/chat-tasks-utilities.md#chatoutput)**.**
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.

***

***

***

## <mark style="color:green;">**ChatPreprocessor**</mark>

Create message template for input prompt. Subclass of [**Action**](/core/action.md). Type of [**Action**](/core/action.md)**\[Dict\[str, Any], Dict\[str, Any]].**

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):** \
  Expected keys:
  * <mark style="color:red;">**"prompt"**</mark>**&#x20;(str):** Input prompt;

#### Returns:

* **Dict\[str, Any]:** \
  Expected keys:
  * <mark style="color:red;">**"messages"**</mark>**&#x20;(Iterable\[ChatCompletionMessageParam]):** Input messages;

***

***

***

## <mark style="color:green;">**ChatPostprocessor**</mark>

Process API output. Subclass of [**Action**](/core/action.md). Type of [**Action**](/core/action.md)**\[Dict\[str, Any], Dict\[str, Any]].**

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):** \
  Expected keys:
  * <mark style="color:red;">**"output"**</mark>**&#x20;(List\[Dict\[str, Any]]):** Expected keys:
    * <mark style="color:purple;">**"generated\_text"**</mark>**&#x20;(str)**;

#### Returns:

* **str:** Response message.

***

***
