The ChatDefinition allows users to turn any flow into a Chat flow by
defining what has to run and what are the inputs and outputs.
The ChatDefinition requires a function, inputs(optional) and
output_key(optional).
The function receives a dictionary as input and can output a string or a
dict. If the output is a dict, then an output_key must be provided.
Anything can run inside the function. You can also pass methods of
pre-built classes like a Chain.
Here's an example of how to use it in a CustomComponent:
```python
from langflow import CustomComponent
from langflow.utils.chat import ChatDefinition
class Component(CustomComponent):
documentation: str = "http://docs.langflow.org/components/custom"
def build(self) -> Data:
def func(inputs, callbacks):
return {"text":'This is a simple example.'}
return ChatDefinition(func=func, inputs=[], output_key="text")
```
refactor(App.tsx): remove hardReset function call and add comment indicating any reset function
refactor(flowsContext.tsx): remove hardReset function and update comment for tabId property
refactor(flowsContext.tsx): remove hardReset function from useEffect hook
refactor(flowsContext.tsx): remove hardReset function and update comment for hardReset function
refactor(flowManagerStore.ts): add nodeId property and incrementNodeId function
refactor(tabs/index.ts): remove hardReset function from FlowsContextType
The flowManagerStore.ts file is added to the src/frontend/src/stores directory. This file contains the implementation of a custom store called RFState, which manages the state of nodes and edges in a reactflow component. The store provides various functions and callbacks to manipulate and update the nodes and edges.
The RFState interface defines the structure of the store, including the nodes and edges arrays, as well as callbacks for handling changes to nodes and edges.
The useStore hook is created using the create function from the zustand library. It initializes the store with an empty nodes and edges array, and defines callbacks for handling changes to nodes, edges, and connections.
The setEdges and setNodes functions are used to update the nodes and edges arrays in the store.
The deleteNode function removes a node from the nodes array and any associated edges from the edges array.
The deleteEdge function removes an edge from the edges array.
This store can be used in components to access and manipulate the nodes and edges in a reactflow component.