---
license: mit
---
# Table of Contents
* [\_\_init\_\_](#__init__)
* [DemonstrationsAtomicFlow](#DemonstrationsAtomicFlow)
* [DemonstrationsAtomicFlow](#DemonstrationsAtomicFlow.DemonstrationsAtomicFlow)
* [instantiate\_from\_config](#DemonstrationsAtomicFlow.DemonstrationsAtomicFlow.instantiate_from_config)
* [run](#DemonstrationsAtomicFlow.DemonstrationsAtomicFlow.run)
* [ChatWithDemonstrationsFlow](#ChatWithDemonstrationsFlow)
* [ChatWithDemonstrationsFlow](#ChatWithDemonstrationsFlow.ChatWithDemonstrationsFlow)
# \_\_init\_\_
# DemonstrationsAtomicFlow
## DemonstrationsAtomicFlow Objects
```python
class DemonstrationsAtomicFlow(AtomicFlow)
```
This class implements a Demonstrations Atomic Flow. It is a flow which is usually used to pass demonstrations (of user assistant interactions)
to the ChatAtomicFlow.
*Configuration Parameters*:
- `name` (str): The name of the flow. Default: "DemonstrationsAtomicFlow"
- `description` (str): A description of the flow. This description is used to generate the help message of the flow.
Default: "A flow that passes demonstrations to the ChatFlow"
- `data` (List[Dict[str, Any]]): The data of the demonstrations.
If data is None, the data is loaded from the file specified in the params["data_dir"].
Default: No default value this field must be set.
- `params` (Dict[str, Any]): The parameters specific to the dataset of the demonstrations. Its default parameters are:
- `data_dir` (str): The directory where the demonstrations are stored. If the data is not directly passed to the flow through `data` then
the data is loaded from this directory. Default: No default value this field must be set.
- `demonstrations_id` (str): The id of the demonstrations (name of the data file). If the data is not directly passed to the flow through `data` then
the data is loaded from this file. Default: No default value this field must be set.
- `demonstrations_k` (int): The number of demonstrations to pass to the ChatFlow.
If None, all the demonstrations are passed to the ChatFlow. Default: None
- `query_prompt_template` (Dict[str, Any]): The prompt template used to generate the query of the demonstrations.
By default its of type flows.prompt_template.JinjaPrompt. None of the parameters of the prompt are defined by default and therefore need to be defined if one
wants to use the query_prompt_template. Default parameters are defined in flows.prompt_template.jinja2_prompts.JinjaPrompt.
- `response_prompt_template` (Dict[str, Any]): The prompt template used to generate the response of the demonstrations. By default its of type flows.prompt_template.JinjaPrompt.
None of the parameters of the prompt are defined by default and therefore need to be defined if one
wants to use the response_prompt_template. Default parameters are defined in flows.prompt_template.jinja2_prompts.JinjaPrompt.
*Input Interface*:
- The input interface expected by its successor flow (e.g. typically ChatAtomicFlow so the input interface is the one expected by ChatAtomicFlow)
*Output Interface*:
- The input interface expected by its successor flow (e.g. typically ChatAtomicFlow so the input interface expected by ChatAtomicFlow))
- `demonstrations` (List[Dict[str, Any]]): A list of demonstrations. Each demonstration is a dictionary with the following keys:
- idx (int): The index of the demonstration
- query (str): The query of the demonstration
- response (str): The response of the demonstration
**Arguments**:
- `params` (`Dict[str, Any]`): The parameters specific to the dataset of the demonstrations. It must sould contain the following keys:
- 'data_dir' (str): The directory where the demonstrations are stored. This field is used if the data is not directly passed to the flow through the 'data' field.
- 'demonstrations_id' (str): The id of the demonstrations (name of the data file). This field is used if the data is not directly passed to the flow through the 'data' field.
- 'demonstrations_k' (int): The number of demonstrations to pass to the ChatFlow. If None, all the demonstrations are passed to the ChatFlow.
- 'ids_to_keep' (Optional[Union[str, List[str]]]): The ids of the demonstrations to keep. If None, all the demonstrations are kept.
- `query_prompt_template` (`JinjaPrompt`): The prompt template used to generate the query of the demonstrations.
- `response_prompt_template` (`JinjaPrompt`): The prompt template used to generate the response of the demonstrations.
- `data` (`Optional[List[Dict[str, Any]]]`): The data of the demonstrations. If None, the data is loaded from the file specified in the params.
#### instantiate\_from\_config
```python
@classmethod
def instantiate_from_config(cls, config)
```
This method instantiates the flow from a config file.
**Arguments**:
- `config` (`Dict[str, Any]`): The configuration of the flow.
**Returns**:
`Flow`: The instantiated flow.
#### run
```python
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
```
This method runs the flow. It returns the input data of the flow with the demonstrations added to it.
**Arguments**:
- `input_data` (`Dict[str, Any]`): The input data of the flow.
**Returns**:
`Dict[str, Any]`: The input data of the flow with the demonstrations added to it.
# ChatWithDemonstrationsFlow
## ChatWithDemonstrationsFlow Objects
```python
class ChatWithDemonstrationsFlow(SequentialFlow)
```
A Chat with Demonstrations Flow. It is a flow that consists of multiple sub-flows that are executed sequentially.
It's parent class is SequentialFlow.
It Contains the following subflows:
- A Demonstration Flow: It is a flow that passes demonstrations to the ChatFlow
- A Chat Flow: It is a flow that uses the demonstrations to answer queries asked by the user/human.
An illustration of the flow is as follows:
-------> Demonstration Flow -------> Chat Flow ------->
*Configuration Parameters*:
- `name` (str): The name of the flow. Default: "ChatAtomic_Flow_with_Demonstrations"
- `description` (str): A description of the flow. This description is used to generate the help message of the flow.
Default: "A sequential flow that answers questions with demonstrations"
- `subflows_config` (Dict[str,Any]): A dictionary of subflows configurations of the sequential Flow. Default:
- `Demonstration Flow`: The configuration of the Demonstration Flow. By default, it a DemonstrationsAtomicFlow.
Its default parmaters are defined in DemonstrationsAtomicFlow).
- `Chat Flow`: The configuration of the Chat Flow. By default, its a ChatAtomicFlow.
Its default parmaters are defined in ChatAtomicFlowModule (see Flowcard, i.e. README.md, of ChatAtomicFlowModule).
- `topology` (str): The topology of the flow which is "sequential". By default, the topology is the one shown in the
illustration above (the topology is also described in ChatWithDemonstrationsFlow.yaml).
*Input Interface*:
- `query` (str): A query asked to the flow (e.g. "What is the capital of France?")
Output Interface:
- `answer` (str): The answer of the flow to the query
**Arguments**:
- `\**kwargs`: Arguments to be passed to the parent class SequentialFlow constructor.