Skip to content

Commit 8ad1ad6

Browse files
authored
feat(api): rename add_flow_def() to open_flow() (#830)
1 parent df8c96d commit 8ad1ad6

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

docs/docs/core/flow_def.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ It takes two arguments:
3333
* `flow_builder`: a `FlowBuilder` object to help build the flow.
3434
* `data_scope`: a `DataScope` object, representing the top-level data scope. Any data created by the flow should be added to it.
3535

36-
Alternatively, for more flexibility (e.g. you want to do this conditionally or generate dynamic name), you can explicitly call the `cocoindex.add_flow_def()` method:
36+
Alternatively, for more flexibility (e.g. you want to do this conditionally or generate dynamic name), you can explicitly call the `cocoindex.open_flow()` method:
3737

3838
```python
3939
def demo_flow_def(flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataScope):
4040
...
4141

4242
# Add the flow definition to the flow registry.
43-
demo_flow = cocoindex.add_flow_def("DemoFlow", demo_flow_def)
43+
demo_flow = cocoindex.open_flow("DemoFlow", demo_flow_def)
4444
```
4545

4646
In both cases, `demo_flow` will be an object with `cocoindex.Flow` class type.

python/cocoindex/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from .flow import flow_def
1212
from .flow import EvaluateAndDumpOptions, GeneratedField
1313
from .flow import FlowLiveUpdater, FlowLiveUpdaterOptions, FlowUpdaterStatusUpdates
14-
from .flow import add_flow_def, remove_flow
14+
from .flow import open_flow
15+
from .flow import add_flow_def, remove_flow # DEPRECATED
1516
from .flow import update_all_flows_async, setup_all_flows, drop_all_flows
1617
from .lib import init, start_server, stop
1718
from .llm import LlmSpec, LlmApiType
@@ -57,8 +58,9 @@
5758
"FlowLiveUpdater",
5859
"FlowLiveUpdaterOptions",
5960
"FlowUpdaterStatusUpdates",
60-
"add_flow_def",
61-
"remove_flow",
61+
"open_flow",
62+
"add_flow_def", # DEPRECATED
63+
"remove_flow", # DEPRECATED
6264
"update_all_flows_async",
6365
"setup_all_flows",
6466
"drop_all_flows",

python/cocoindex/flow.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,24 @@ def get_flow_full_name(name: str) -> str:
857857
return f"{setting.get_app_namespace(trailing_delimiter='.')}{name}"
858858

859859

860-
def add_flow_def(name: str, fl_def: Callable[[FlowBuilder, DataScope], None]) -> Flow:
860+
def open_flow(name: str, fl_def: Callable[[FlowBuilder, DataScope], None]) -> Flow:
861+
"""
862+
Open a flow, with the given name and definition.
863+
"""
861864
with _flows_lock:
862865
if name in _flows:
863866
raise KeyError(f"Flow with name {name} already exists")
864867
fl = _flows[name] = _create_lazy_flow(name, fl_def)
865868
return fl
866869

867870

871+
def add_flow_def(name: str, fl_def: Callable[[FlowBuilder, DataScope], None]) -> Flow:
872+
"""
873+
DEPRECATED: Use `open_flow()` instead.
874+
"""
875+
return open_flow(name, fl_def)
876+
877+
868878
def remove_flow(fl: Flow) -> None:
869879
"""
870880
DEPRECATED: Use `Flow.close()` instead.
@@ -878,7 +888,7 @@ def flow_def(
878888
"""
879889
A decorator to wrap the flow definition.
880890
"""
881-
return lambda fl_def: add_flow_def(name or fl_def.__name__, fl_def)
891+
return lambda fl_def: open_flow(name or fl_def.__name__, fl_def)
882892

883893

884894
def flow_names() -> list[str]:

0 commit comments

Comments
 (0)