TextToTextGenerationTask
Task for open-ended text generation using large language models.
Text-to-text generation takes a natural-language prompt (user message) and
produces a natural-language response. The task maintains a conversation
history (USE_HISTORY = True) so that multi-turn chat interactions are
supported out of the box. Input and output are both plain strings, formatted
as OpenAI-style chat messages (role/content dicts) before being
passed to the underlying LLM.
Compatible models include all DashAI LLM wrappers (Llama, Mistral, Mixtral,
Qwen, SmolLM) which implement the generate method.
Methods
prepare_for_task(self, input: List[DashAI.back.dependencies.database.models.ProcessData], history: Optional[List[Tuple[str, str]]] = None) -> list[dict[str, str]]
TextToTextGenerationTaskPrepare the input by including the history.
Parameters
- input : str
- The current input to be processed. E.g.: ["Tell me a joke."]
- history : Optional[List[Tuple[str, str]]], optional
- The history of previous inputs and outputs, by default None. E.g.: [("Hello!", "Hello! How can I assist you today?")]
Returns
- str
- The input prepared with the history to be used by the model. E.g.: [{"role": "user", "content": "Hello!"}, {"role": "assistant", "content": "Hello! How can I assist you today?"}, {"role": "user", "content": "Tell me a joke."}]
prepare_input_for_database(self, input: List[str], **kwargs: Any) -> List[Tuple[str, str]]
TextToTextGenerationTaskPrepare the input for the database.
Parameters
- input : str
- The input to be prepared.
Returns
- List[Tuple[str, str]]
- Input with the new types as a list of tuples containing the data and its type
process_input_from_database(self, input: List[DashAI.back.dependencies.database.models.ProcessData], **kwargs: Any) -> List[DashAI.back.dependencies.database.models.ProcessData]
TextToTextGenerationTaskProcess the input from the database.
Parameters
- input : list[str]
- The input data to be processed.
Returns
- list[str]
- The processed input data.
process_output(self, output: List[Any], **kwargs: Any) -> List[Tuple[str, str]]
TextToTextGenerationTaskConvert raw model output to a storable (text, type) pair.
Parameters
- output : list of Any
- Raw output from the generative model. The first element is cast to
strand returned. - **kwargs : dict
- Additional keyword arguments (e.g.
file_name,path). Currently unused; present for interface compatibility.
Returns
- list of tuple of (str, str)
- A single-element list containing
(str(output[0]), "str").
process_output_from_database(self, output: List[DashAI.back.dependencies.database.models.ProcessData], **kwargs: Any) -> List[DashAI.back.dependencies.database.models.ProcessData]
TextToTextGenerationTaskProcess the output from the database.
Parameters
- output : list[str]
- The output data to be processed.
Returns
- list[str]
- The processed output data.
get_metadata(cls) -> Dict[str, Any]
BaseGenerativeTaskReturn serialisable metadata for the current generative task.
Parameters
- cls : type
- The task class (injected automatically by Python for classmethods).
Returns
- Dict[str, Any]
- Dictionary with keys
"inputs_types","outputs_types","inputs_cardinality", and"outputs_cardinality".