nbaldwin commited on
Commit
e00d074
1 Parent(s): b52e939

first commit

Browse files
Files changed (7) hide show
  1. .gitignore +443 -0
  2. ChatHumanFlowModule.py +55 -0
  3. ChatHumanFlowModule.yaml +67 -0
  4. __init__.py +11 -0
  5. demo.yaml +31 -0
  6. pip_requirements.txt +0 -0
  7. run.py +77 -0
.gitignore ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Created by https://www.toptal.com/developers/gitignore/api/python,java,c++,pycharm,visualstudiocode,macos,linux,windows
2
+ # Edit at https://www.toptal.com/developers/gitignore?templates=python,java,c++,pycharm,visualstudiocode,macos,linux,windows
3
+
4
+ ### C++ ###
5
+ # Prerequisites
6
+ *.d
7
+
8
+ # Compiled Object files
9
+ *.slo
10
+ *.lo
11
+ *.o
12
+ *.obj
13
+
14
+ # Precompiled Headers
15
+ *.gch
16
+ *.pch
17
+
18
+ # Compiled Dynamic libraries
19
+ *.so
20
+ *.dylib
21
+ *.dll
22
+
23
+ # Fortran module files
24
+ *.mod
25
+ *.smod
26
+
27
+ # Compiled Static libraries
28
+ *.lai
29
+ *.la
30
+ *.a
31
+ *.lib
32
+
33
+ # Executables
34
+ *.exe
35
+ *.out
36
+ *.app
37
+
38
+ ### Java ###
39
+ # Compiled class file
40
+ *.class
41
+
42
+ # Log file
43
+ *.log
44
+
45
+ # BlueJ files
46
+ *.ctxt
47
+
48
+ # Mobile Tools for Java (J2ME)
49
+ .mtj.tmp/
50
+
51
+ # Package Files #
52
+ *.jar
53
+ *.war
54
+ *.nar
55
+ *.ear
56
+ *.zip
57
+ *.tar.gz
58
+ *.rar
59
+
60
+ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
61
+ hs_err_pid*
62
+ replay_pid*
63
+
64
+ ### Linux ###
65
+ *~
66
+
67
+ # temporary files which can be created if a process still has a handle open of a deleted file
68
+ .fuse_hidden*
69
+
70
+ # KDE directory preferences
71
+ .directory
72
+
73
+ # Linux trash folder which might appear on any partition or disk
74
+ .Trash-*
75
+
76
+ # .nfs files are created when an open file is removed but is still being accessed
77
+ .nfs*
78
+
79
+ ### macOS ###
80
+ # General
81
+ .DS_Store
82
+ .AppleDouble
83
+ .LSOverride
84
+
85
+ # Icon must end with two \r
86
+ Icon
87
+
88
+
89
+ # Thumbnails
90
+ ._*
91
+
92
+ # Files that might appear in the root of a volume
93
+ .DocumentRevisions-V100
94
+ .fseventsd
95
+ .Spotlight-V100
96
+ .TemporaryItems
97
+ .Trashes
98
+ .VolumeIcon.icns
99
+ .com.apple.timemachine.donotpresent
100
+
101
+ # Directories potentially created on remote AFP share
102
+ .AppleDB
103
+ .AppleDesktop
104
+ Network Trash Folder
105
+ Temporary Items
106
+ .apdisk
107
+
108
+ ### macOS Patch ###
109
+ # iCloud generated files
110
+ *.icloud
111
+
112
+ ### PyCharm ###
113
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
114
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
115
+
116
+ # User-specific stuff
117
+ .idea/**/workspace.xml
118
+ .idea/**/tasks.xml
119
+ .idea/**/usage.statistics.xml
120
+ .idea/**/dictionaries
121
+ .idea/**/shelf
122
+
123
+ # AWS User-specific
124
+ .idea/**/aws.xml
125
+
126
+ # Generated files
127
+ .idea/**/contentModel.xml
128
+
129
+ # Sensitive or high-churn files
130
+ .idea/**/dataSources/
131
+ .idea/**/dataSources.ids
132
+ .idea/**/dataSources.local.xml
133
+ .idea/**/sqlDataSources.xml
134
+ .idea/**/dynamic.xml
135
+ .idea/**/uiDesigner.xml
136
+ .idea/**/dbnavigator.xml
137
+
138
+ # Gradle
139
+ .idea/**/gradle.xml
140
+ .idea/**/libraries
141
+
142
+ # Gradle and Maven with auto-import
143
+ # When using Gradle or Maven with auto-import, you should exclude module files,
144
+ # since they will be recreated, and may cause churn. Uncomment if using
145
+ # auto-import.
146
+ # .idea/artifacts
147
+ # .idea/compiler.xml
148
+ # .idea/jarRepositories.xml
149
+ # .idea/modules.xml
150
+ # .idea/*.iml
151
+ # .idea/modules
152
+ # *.iml
153
+ # *.ipr
154
+
155
+ # CMake
156
+ cmake-build-*/
157
+
158
+ # Mongo Explorer plugin
159
+ .idea/**/mongoSettings.xml
160
+
161
+ # File-based project format
162
+ *.iws
163
+
164
+ # IntelliJ
165
+ out/
166
+
167
+ # mpeltonen/sbt-idea plugin
168
+ .idea_modules/
169
+
170
+ # JIRA plugin
171
+ atlassian-ide-plugin.xml
172
+
173
+ # Cursive Clojure plugin
174
+ .idea/replstate.xml
175
+
176
+ # SonarLint plugin
177
+ .idea/sonarlint/
178
+
179
+ # Crashlytics plugin (for Android Studio and IntelliJ)
180
+ com_crashlytics_export_strings.xml
181
+ crashlytics.properties
182
+ crashlytics-build.properties
183
+ fabric.properties
184
+
185
+ # Editor-based Rest Client
186
+ .idea/httpRequests
187
+
188
+ # Android studio 3.1+ serialized cache file
189
+ .idea/caches/build_file_checksums.ser
190
+
191
+ ### PyCharm Patch ###
192
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
193
+
194
+ # *.iml
195
+ # modules.xml
196
+ # .idea/misc.xml
197
+ # *.ipr
198
+
199
+ # Sonarlint plugin
200
+ # https://plugins.jetbrains.com/plugin/7973-sonarlint
201
+ .idea/**/sonarlint/
202
+
203
+ # SonarQube Plugin
204
+ # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
205
+ .idea/**/sonarIssues.xml
206
+
207
+ # Markdown Navigator plugin
208
+ # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
209
+ .idea/**/markdown-navigator.xml
210
+ .idea/**/markdown-navigator-enh.xml
211
+ .idea/**/markdown-navigator/
212
+
213
+ # Cache file creation bug
214
+ # See https://youtrack.jetbrains.com/issue/JBR-2257
215
+ .idea/$CACHE_FILE$
216
+
217
+ # CodeStream plugin
218
+ # https://plugins.jetbrains.com/plugin/12206-codestream
219
+ .idea/codestream.xml
220
+
221
+ # Azure Toolkit for IntelliJ plugin
222
+ # https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
223
+ .idea/**/azureSettings.xml
224
+
225
+ ### Python ###
226
+ # Byte-compiled / optimized / DLL files
227
+ __pycache__/
228
+ *.py[cod]
229
+ *$py.class
230
+
231
+ # C extensions
232
+
233
+ # Distribution / packaging
234
+ .Python
235
+ build/
236
+ develop-eggs/
237
+ dist/
238
+ downloads/
239
+ eggs/
240
+ .eggs/
241
+ lib/
242
+ lib64/
243
+ parts/
244
+ sdist/
245
+ var/
246
+ wheels/
247
+ share/python-wheels/
248
+ *.egg-info/
249
+ .installed.cfg
250
+ *.egg
251
+ MANIFEST
252
+
253
+ # PyInstaller
254
+ # Usually these files are written by a python script from a template
255
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
256
+ *.manifest
257
+ *.spec
258
+
259
+ # Installer logs
260
+ pip-log.txt
261
+ pip-delete-this-directory.txt
262
+
263
+ # Unit test / coverage reports
264
+ htmlcov/
265
+ .tox/
266
+ .nox/
267
+ .coverage
268
+ .coverage.*
269
+ .cache
270
+ nosetests.xml
271
+ coverage.xml
272
+ *.cover
273
+ *.py,cover
274
+ .hypothesis/
275
+ .pytest_cache/
276
+ cover/
277
+
278
+ # Translations
279
+ *.mo
280
+ *.pot
281
+
282
+ # Django stuff:
283
+ local_settings.py
284
+ db.sqlite3
285
+ db.sqlite3-journal
286
+
287
+ # Flask stuff:
288
+ instance/
289
+ .webassets-cache
290
+
291
+ # Scrapy stuff:
292
+ .scrapy
293
+
294
+ # Sphinx documentation
295
+ docs/_build/
296
+
297
+ # PyBuilder
298
+ .pybuilder/
299
+ target/
300
+
301
+ # Jupyter Notebook
302
+ .ipynb_checkpoints
303
+
304
+ # IPython
305
+ profile_default/
306
+ ipython_config.py
307
+
308
+ # pyenv
309
+ # For a library or package, you might want to ignore these files since the code is
310
+ # intended to run in multiple environments; otherwise, check them in:
311
+ # .python-version
312
+
313
+ # pipenv
314
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
315
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
316
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
317
+ # install all needed dependencies.
318
+ #Pipfile.lock
319
+
320
+ # poetry
321
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
322
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
323
+ # commonly ignored for libraries.
324
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
325
+ #poetry.lock
326
+
327
+ # pdm
328
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
329
+ #pdm.lock
330
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
331
+ # in version control.
332
+ # https://pdm.fming.dev/#use-with-ide
333
+ .pdm.toml
334
+
335
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
336
+ __pypackages__/
337
+
338
+ # Celery stuff
339
+ celerybeat-schedule
340
+ celerybeat.pid
341
+
342
+ # SageMath parsed files
343
+ *.sage.py
344
+
345
+ # Environments
346
+ .env
347
+ .venv
348
+ env/
349
+ venv/
350
+ ENV/
351
+ env.bak/
352
+ venv.bak/
353
+
354
+ # Spyder project settings
355
+ .spyderproject
356
+ .spyproject
357
+
358
+ # Rope project settings
359
+ .ropeproject
360
+
361
+ # mkdocs documentation
362
+ /site
363
+
364
+ # mypy
365
+ .mypy_cache/
366
+ .dmypy.json
367
+ dmypy.json
368
+
369
+ # Pyre type checker
370
+ .pyre/
371
+
372
+ # pytype static type analyzer
373
+ .pytype/
374
+
375
+ # Cython debug symbols
376
+ cython_debug/
377
+
378
+ # PyCharm
379
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
380
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
381
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
382
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
383
+ #.idea/
384
+
385
+ ### Python Patch ###
386
+ # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
387
+ poetry.toml
388
+
389
+ # ruff
390
+ .ruff_cache/
391
+
392
+ # LSP config files
393
+ pyrightconfig.json
394
+
395
+ ### VisualStudioCode ###
396
+ .vscode/*
397
+ !.vscode/settings.json
398
+ !.vscode/tasks.json
399
+ !.vscode/launch.json
400
+ !.vscode/extensions.json
401
+ !.vscode/*.code-snippets
402
+
403
+ # Local History for Visual Studio Code
404
+ .history/
405
+
406
+ # Built Visual Studio Code Extensions
407
+ *.vsix
408
+
409
+ ### VisualStudioCode Patch ###
410
+ # Ignore all local history of files
411
+ .history
412
+ .ionide
413
+
414
+ ### Windows ###
415
+ # Windows thumbnail cache files
416
+ Thumbs.db
417
+ Thumbs.db:encryptable
418
+ ehthumbs.db
419
+ ehthumbs_vista.db
420
+
421
+ # Dump file
422
+ *.stackdump
423
+
424
+ # Folder config file
425
+ [Dd]esktop.ini
426
+
427
+ # Recycle Bin used on file shares
428
+ $RECYCLE.BIN/
429
+
430
+ # Windows Installer files
431
+ *.cab
432
+ *.msi
433
+ *.msix
434
+ *.msm
435
+ *.msp
436
+
437
+ # Windows shortcuts
438
+ *.lnk
439
+
440
+ # End of https://www.toptal.com/developers/gitignore/api/python,java,c++,pycharm,visualstudiocode,macos,linux,windows
441
+
442
+ .*
443
+ flow_modules/
ChatHumanFlowModule.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flows.base_flows import CircularFlow
2
+ from flows.utils import logging
3
+
4
+ log = logging.get_logger(f"flows.{__name__}")
5
+
6
+
7
+ class ChatHumanFlowModule(CircularFlow):
8
+ """ This class implements a Chat Human Flow Module. It is a flow that consists of two sub-flows that are executed circularly. It Contains the following subflows:
9
+
10
+ - A User Flow: A flow makes queries to the Assistant Flow. E.g. The user asks the assistant (LLM) a question.
11
+ - A Assistant Flow: A flow that responds to queries made by the User Flow. E.g. The assistant (LLM) answers the user's question.
12
+
13
+ To end the interaction, the user must type "\<END\>"
14
+
15
+ An illustration of the flow is as follows:
16
+
17
+ |------> User Flow -----------> |
18
+ ^ |
19
+ | |
20
+ | v
21
+ |<------ Assistant Flow <-------|
22
+
23
+ *Configuration Parameters*:
24
+
25
+ - `name` (str): The name of the flow. Default: "ChatHumanFlowModule"
26
+ - `description` (str): A description of the flow. This description is used to generate the help message of the flow.
27
+ Default: "Flow that enables chatting between a ChatAtomicFlow and a user providing the input."
28
+ - `max_rounds` (int): The maximum number of rounds the flow can run for. Default: None, which means that there is no limit on the number of rounds.
29
+ - `early_exit_key` (str): The key that is used to exit the flow. Default: "end_of_interaction"
30
+ - `subflows_config` (Dict[str,Any]): A dictionary of subflows configurations. Default:
31
+ - `Assistant Flow`: The configuration of the Assistant Flow. By default, it a ChatAtomicFlow. It default parmaters are defined in ChatAtomicFlowModule.
32
+ - `User Flow`: The configuration of the User Flow. By default, it a HumanStandardInputFlow. It default parmaters are defined in HumanStandardInputFlowModule.
33
+ - `topology` (str): (List[Dict[str,Any]]): The topology of the flow which is "circular".
34
+ By default, the topology is the one shown in the illustration above (the topology is also described in ChatHumanFlowModule.yaml).
35
+
36
+ *Input Interface*:
37
+
38
+ - None. By default, the input interface doesn't expect any input.
39
+
40
+ *Output Interface*:
41
+
42
+ - `end_of_interaction` (bool): Whether the interaction is finished or not.
43
+
44
+ :param \**kwargs: Arguments to be passed to the parent class CircularFlow constructor.
45
+ :type \**kwargs: Dict[str, Any]
46
+ """
47
+
48
+
49
+ def __init__(self, **kwargs):
50
+ super().__init__(**kwargs)
51
+
52
+ @classmethod
53
+ def type(cls):
54
+ """ This method returns the type of the flow."""
55
+ return "OpenAIChatHumanFlowModule"
ChatHumanFlowModule.yaml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "ChatInteractiveFlow"
2
+ description: "Flow that enables chatting between a ChatAtomicFlow and a user providing the input."
3
+
4
+ max_rounds: null # Run until early exit is detected
5
+
6
+ input_interface:
7
+ _target_: flows.interfaces.KeyInterface
8
+
9
+ output_interface:
10
+ - "end_of_interaction"
11
+ - "answer"
12
+
13
+ subflows_config:
14
+ Assistant:
15
+ _target_: aiflows.ChatFlowModule.ChatAtomicFlow.instantiate_from_default_config
16
+ User:
17
+ _target_: aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow.instantiate_from_default_config
18
+
19
+ topology:
20
+ - goal: "Query the assistant"
21
+
22
+ ### Input Interface
23
+ input_interface:
24
+ _target_: flows.interfaces.KeyInterface
25
+ additional_transformations:
26
+ - _target_: flows.data_transformations.KeyMatchInput
27
+
28
+ ### Flow Specification
29
+ flow: Assistant
30
+ reset_every_round: false
31
+
32
+ ### Output Interface
33
+ output_interface:
34
+ _target_: flows.interfaces.KeyInterface
35
+ additional_transformations:
36
+ - _target_: flows.data_transformations.PrintPreviousMessages
37
+
38
+ - goal: "Ask the user for input"
39
+
40
+ ### Input Interface
41
+ input_interface:
42
+ _target_: flows.interfaces.KeyInterface
43
+ additional_transformations:
44
+ - _target_: flows.data_transformations.KeyMatchInput
45
+
46
+ ### Flow Specification
47
+ flow: User
48
+ reset_every_round: true
49
+
50
+ ### Output Interface
51
+ output_interface:
52
+ _target_: flows.interfaces.KeyInterface
53
+ keys_to_rename:
54
+ human_input: query
55
+ additional_transformations:
56
+ - _target_: flows.data_transformations.RegexFirstOccurrenceExtractor
57
+ regex: '(?<=```answer)([\s\S]*?)(?=```)'
58
+ input_key: "query"
59
+ output_key: "answer"
60
+ strip: True
61
+ assert_unique: True
62
+ - _target_: flows.data_transformations.EndOfInteraction
63
+ end_of_interaction_string: "<END>"
64
+ input_key: "query"
65
+ output_key: "end_of_interaction"
66
+
67
+ early_exit_key: "end_of_interaction"
__init__.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ~~~ Specify the dependencies ~~~
2
+ dependencies = [
3
+ {"url": "aiflows/ChatFlowModule", "revision": "main"},
4
+ {"url": "aiflows/HumanStandardInputFlowModule", "revision": "main"},
5
+ ]
6
+ from flows import flow_verse
7
+
8
+ flow_verse.sync_dependencies(dependencies)
9
+ # ~~~
10
+
11
+ from .ChatHumanFlowModule import ChatHumanFlowModule
demo.yaml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ flow:
4
+ max_rounds: 5
5
+ _target_: aiflows.ChatInteractiveFlowModule.ChatHumanFlowModule.instantiate_from_default_config
6
+ subflows_config:
7
+ Assistant:
8
+ _target_: aiflows.ChatFlowModule.ChatAtomicFlow.instantiate_from_default_config
9
+ backend:
10
+ _target_: flows.backends.llm_lite.LiteLLMBackend
11
+ api_infos: ???
12
+ model_name:
13
+ openai: "gpt-4"
14
+ azure: "azure/gpt-4"
15
+ input_interface_non_initialized: []
16
+
17
+ User:
18
+ _target_: aiflows.HumanStandardInputFlowModule.HumanStandardInputFlow.instantiate_from_default_config
19
+ request_multi_line_input_flag: False
20
+ query_message_prompt_template:
21
+ _target_: flows.prompt_template.JinjaPrompt
22
+ template: |2-
23
+ {{api_output}}
24
+
25
+ To end an Interaction, type <END> and press enter.
26
+
27
+ input_variables: ["api_output"]
28
+ input_interface:
29
+ - "api_output"
30
+ output_interface:
31
+ - "human_input"
pip_requirements.txt ADDED
File without changes
run.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """A simple script to run a Flow that can be used for development and debugging."""
2
+
3
+ import os
4
+
5
+ import hydra
6
+
7
+ import flows
8
+ from flows.flow_launchers import FlowLauncher
9
+ from flows.backends.api_info import ApiInfo
10
+ from flows.utils.general_helpers import read_yaml_file
11
+
12
+ from flows import logging
13
+ from flows.flow_cache import CACHING_PARAMETERS, clear_cache
14
+
15
+ CACHING_PARAMETERS.do_caching = False # Set to True to enable caching
16
+ # clear_cache() # Uncomment this line to clear the cache
17
+
18
+ logging.set_verbosity_debug()
19
+
20
+ dependencies = [
21
+ {"url": "aiflows/ChatInteractiveFlowModule", "revision": os.getcwd()},
22
+ ]
23
+ from flows import flow_verse
24
+ flow_verse.sync_dependencies(dependencies)
25
+
26
+ if __name__ == "__main__":
27
+ # ~~~ Set the API information ~~~
28
+ # OpenAI backend
29
+
30
+ api_information = [ApiInfo(backend_used="openai",
31
+ api_key = os.getenv("OPENAI_API_KEY"))]
32
+
33
+
34
+ # # Azure backend
35
+ # api_information = ApiInfo(backend_used = "azure",
36
+ # api_base = os.getenv("AZURE_API_BASE"),
37
+ # api_key = os.getenv("AZURE_OPENAI_KEY"),
38
+ # api_version = os.getenv("AZURE_API_VERSION") )
39
+
40
+ root_dir = "."
41
+ cfg_path = os.path.join(root_dir, "demo.yaml")
42
+ cfg = read_yaml_file(cfg_path)
43
+
44
+ cfg["flow"]["subflows_config"]["Assistant"]["backend"]["api_infos"] = api_information
45
+
46
+ # ~~~ Instantiate the Flow ~~~
47
+ flow_with_interfaces = {
48
+ "flow": hydra.utils.instantiate(cfg['flow'], _recursive_=False, _convert_="partial"),
49
+ "input_interface": (
50
+ None
51
+ if cfg.get( "input_interface", None) is None
52
+ else hydra.utils.instantiate(cfg['input_interface'], _recursive_=False)
53
+ ),
54
+ "output_interface": (
55
+ None
56
+ if cfg.get( "output_interface", None) is None
57
+ else hydra.utils.instantiate(cfg['output_interface'], _recursive_=False)
58
+ ),
59
+ }
60
+ # ~~~ Get the data ~~~
61
+ data = {"id": 0} # This can be a list of samples
62
+ # data = {"id": 0, "question": "Who was the NBA champion in 2023?"} # This can be a list of samples
63
+
64
+ # ~~~ Run inference ~~~
65
+ path_to_output_file = None
66
+ # path_to_output_file = "output.jsonl" # Uncomment this line to save the output to disk
67
+
68
+ _, outputs = FlowLauncher.launch(
69
+ flow_with_interfaces=flow_with_interfaces,
70
+ data=data,
71
+ path_to_output_file=path_to_output_file
72
+ )
73
+
74
+ # ~~~ Print the output ~~~
75
+ flow_output_data = outputs[0]
76
+ print(flow_output_data)
77
+