> 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/openaichat.md).

# OpenAIChat

Basic chat task based on OpenAI API

This task uses[ **OpenAIChatGPTPredictor**](/predictors/openaichatgptpredictor.md). For more details, see:

{% content-ref url="/pages/oEWZA8XgUSyhDADUpwU8" %}
[OpenAIChatGPTPredictor](/predictors/openaichatgptpredictor.md)
{% endcontent-ref %}

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

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

## Methods and properties

Main methods and properties

***

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

#### Arguments:

* <mark style="color:orange;">**predictor**</mark>**&#x20;(**[**OpenAIChatGPTPredictor**](/predictors/openaichatgptpredictor.md)**\[Any, Any]):** Predictor that will be used in task.
* <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: \
  [**OpenAIChatPreprocessor**](#openaichatpreprocessor) **|** [**GetMemory**](/core/memory-management.md#getmemory) **|** [**ChatAddContext**](/tasks/chat-tasks-utilities.md#chataddcontext) **|** [**SetMemory**](/core/memory-management.md#setmemory)
* <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: \
  [**OpenAIChatPostprocessor**](#openaichatpostprocessor) **|** [**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;">**OpenAIChatPreprocessor**</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;">**OpenAIChatPostprocessor**</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;">**"choices"**</mark>**&#x20;(List\[Dict\[str, Any]]):** Expected keys:&#x20;
    * <mark style="color:purple;">**"message"**</mark> (Dict\[str, Any]): Expected keys:&#x20;
      * <mark style="color:blue;">**"content"**</mark> (str);

#### Returns:

* **str:** Response message.

***

***

***

## <mark style="color:green;">**OpenAIChat**</mark><mark style="color:green;">Stream</mark><mark style="color:green;">**Postprocessor**</mark>

Process API stream 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;">**"stream"**</mark>**&#x20;(Iterable\[Dict\[str, Any]]):** Expected keys:
    * <mark style="color:purple;">**"choices"**</mark> **(List\[Dict\[str, Any]]):** Expected keys:&#x20;
      * <mark style="color:blue;">**"delta"**</mark> (Dict\[str, Any]): Expected keys:&#x20;
        * <mark style="color:green;">**"content"**</mark> (str);

#### Returns:

* **Generator\[str, None, None]:** Response chunks.

***

***
