OpenAIChat
Basic chat task based on OpenAI API
This task uses OpenAIChatGPTPredictor. For more details, see:
OpenAIChatGPTPredictorSubclass 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.
preprocess (Optional[Component], optional): Component executed before predictor. If equals to None, default component will be used. Defaults to None. Default component: OpenAIChatPreprocessor | GetMemory | ChatAddContext | SetMemory
postprocess (Optional[Component], optional): Component executed after predictor. If equals to None, default component will be used. Defaults to None. Default component: OpenAIChatPostprocessor | GetMemory | ChatUpdateContext | SetMemory
output_class (Type[NEROutputType], optional): Class for output validation. Defaults to ChatOutput.
name (Optional[str], optional): Name for identification. If equals to None, class name will be used. Defaults to None.
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