OpenAIChat

Basic chat task based on OpenAI API

This task uses OpenAIChatGPTPredictor. For more details, see:

OpenAIChatGPTPredictor

Subclass of Task.

Module: implementation.tasks

Methods and properties

Main methods and properties


__init__

Arguments:

  • predictor (OpenAIChatGPTPredictor[Any, Any]): Predictor that will be used in task.

  • messages (Optional[str], optional): Key to use to access memory for messages. If equals to None, a unique key will be generated. Defaults to None.

Note: This parameter will function as expected only when using the default preprocessor and postprocessor.




OpenAIChatPreprocessor

Create message template for input prompt. Subclass of Action. Type of Action[Dict[str, Any], Dict[str, Any]].


execute

Arguments:

  • input_data (Dict[str, Any]): Expected keys:

    • "prompt" (str): Input prompt;

Returns:

  • Dict[str, Any]: Expected keys:

    • "messages" (Iterable[ChatCompletionMessageParam]): Input messages;




OpenAIChatPostprocessor

Process API output. Subclass of Action. Type of Action[Dict[str, Any], Dict[str, Any]].


execute

Arguments:

  • input_data (Dict[str, Any]): Expected keys:

    • "choices" (List[Dict[str, Any]]): Expected keys:

      • "message" (Dict[str, Any]): Expected keys:

        • "content" (str);

Returns:

  • str: Response message.




OpenAIChatStreamPostprocessor

Process API stream output. Subclass of Action. Type of Action[Dict[str, Any], Dict[str, Any]].


execute

Arguments:

  • input_data (Dict[str, Any]): Expected keys:

    • "stream" (Iterable[Dict[str, Any]]): Expected keys:

      • "choices" (List[Dict[str, Any]]): Expected keys:

        • "delta" (Dict[str, Any]): Expected keys:

          • "content" (str);

Returns:

  • Generator[str, None, None]: Response chunks.



Last updated