nbaldwin commited on
Commit
91ab55c
·
1 Parent(s): 7bc8846

coflows compatible

Browse files
Files changed (5) hide show
  1. .gitignore +443 -0
  2. InterpreterAtomicFlow.py +12 -4
  3. demo.yaml +1 -0
  4. pip_requirements.txt +0 -15
  5. run.py +68 -19
.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/
InterpreterAtomicFlow.py CHANGED
@@ -3,7 +3,7 @@ from copy import deepcopy
3
  from typing import Dict, Any
4
 
5
  from .code_interpreters.create_code_interpreter import create_code_interpreter
6
-
7
  from aiflows.base_flows import AtomicFlow
8
 
9
  def truncate_output(data, max_output_chars=2000):
@@ -126,8 +126,16 @@ class InterpreterAtomicFlow(AtomicFlow):
126
 
127
  def run(
128
  self,
129
- input_data: Dict[str, Any]):
 
 
130
  self._check_input(input_data)
131
  self._process_input_data(input_data)
132
- response = self._call()
133
- return {"interpreter_output": response}
 
 
 
 
 
 
 
3
  from typing import Dict, Any
4
 
5
  from .code_interpreters.create_code_interpreter import create_code_interpreter
6
+ from aiflows.messages import FlowMessage
7
  from aiflows.base_flows import AtomicFlow
8
 
9
  def truncate_output(data, max_output_chars=2000):
 
126
 
127
  def run(
128
  self,
129
+ input_message: FlowMessage):
130
+
131
+ input_data = input_message.data
132
  self._check_input(input_data)
133
  self._process_input_data(input_data)
134
+
135
+ reply = self.package_output_message(
136
+ input_message=input_message,
137
+ response = {"interpreter_output": self._call()}
138
+ )
139
+
140
+ self.send_message(reply)
141
+
demo.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ _target_: flow_modules.aiflows.InterpreterFlowModule.InterpreterAtomicFlow.instantiate_from_default_config
pip_requirements.txt CHANGED
@@ -1,15 +0,0 @@
1
- colorama==0.4.6
2
- pytest==7.3.1
3
- pytest-cov==4.1.0
4
- hydra-core==1.3.2
5
- hydra-colorlog==1.1.0
6
- wrapt-timeout-decorator==1.3.12.2
7
- diskcache==5.6.1
8
- openai==1.0.0
9
- huggingface_hub==0.19.4
10
- jsonlines==3.1.0
11
- jinja2==3.1.2
12
- mock==5.0.2
13
- rich==12.6.0
14
- litellm==1.0.0
15
- aiflows
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
run.py CHANGED
@@ -1,35 +1,67 @@
 
 
1
  import os
2
 
3
  import hydra
4
 
5
- from aiflows.messages import InputMessage
6
- from aiflows.utils.general_helpers import read_yaml_file
 
7
 
8
  from aiflows import logging
9
  from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
10
 
 
 
 
 
 
 
 
11
  CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
12
  # clear_cache() # Uncomment this line to clear the cache
13
 
14
  logging.set_verbosity_debug()
15
- logging.auto_set_dir()
16
 
17
  dependencies = [
18
- {"url": "aiflows/InterpreterFlowModule", "revision": "main"},
19
  ]
20
 
21
  from aiflows import flow_verse
22
-
23
  flow_verse.sync_dependencies(dependencies)
24
-
25
  if __name__ == "__main__":
26
- current_dir = os.getcwd()
27
- cfg_path = os.path.join(current_dir, "InterpreterAtomicFlow.yaml")
28
- cfg = read_yaml_file(cfg_path)
 
 
29
 
30
 
31
- # ~~~ instantiating the flow and input data ~~~
32
- InterpreterFlow = hydra.utils.instantiate(cfg, _recursive_=False, _convert_="partial")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  code = """
34
  print("Hello World!")
35
  """
@@ -37,12 +69,29 @@ print("Hello World!")
37
  "language": "Python",
38
  "code": code,
39
  }
40
- input_message = InputMessage.build(
41
- data_dict=input_data,
42
- src_flow="Launcher",
43
- dst_flow=InterpreterFlow.name
44
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- # ~~~ calling the flow ~~~
47
- output_message = InterpreterFlow(input_message)
48
- print(output_message.data)
 
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 aiflows
8
+ from aiflows.backends.api_info import ApiInfo
9
+ from aiflows.utils.general_helpers import read_yaml_file, quick_load_api_keys
10
 
11
  from aiflows import logging
12
  from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache
13
 
14
+ from aiflows.utils import serve_utils
15
+ from aiflows.workers import run_dispatch_worker_thread
16
+ from aiflows.messages import FlowMessage
17
+ from aiflows.interfaces import KeyInterface
18
+ from aiflows.utils.colink_utils import start_colink_server
19
+ from aiflows.workers import run_dispatch_worker_thread
20
+
21
  CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching
22
  # clear_cache() # Uncomment this line to clear the cache
23
 
24
  logging.set_verbosity_debug()
25
+
26
 
27
  dependencies = [
28
+ {"url": "aiflows/InterpreterFlowModule", "revision": os.getcwd()}
29
  ]
30
 
31
  from aiflows import flow_verse
 
32
  flow_verse.sync_dependencies(dependencies)
 
33
  if __name__ == "__main__":
34
+
35
+ #1. ~~~~~ Set up a colink server ~~~~
36
+ FLOW_MODULES_PATH = "./"
37
+
38
+ cl = start_colink_server()
39
 
40
 
41
+ #2. ~~~~~Load flow config~~~~~~
42
+ root_dir = "."
43
+ cfg_path = os.path.join(root_dir, "demo.yaml")
44
+ cfg = read_yaml_file(cfg_path)
45
+
46
+
47
+ #3. ~~~~ Serve The Flow ~~~~
48
+ serve_utils.serve_flow(
49
+ cl=cl,
50
+ flow_class_name="flow_modules.aiflows.InterpreterFlowModule.InterpreterAtomicFlow",
51
+ flow_endpoint="InterpreterAtomicFlow",
52
+ )
53
+
54
+ #4. ~~~~~Start A Worker Thread~~~~~
55
+ run_dispatch_worker_thread(cl)
56
+
57
+ #5. ~~~~~Mount the flow and get its proxy~~~~~~
58
+ proxy_flow= serve_utils.get_flow_instance(
59
+ cl=cl,
60
+ flow_endpoint="InterpreterAtomicFlow",
61
+ user_id="local",
62
+ )
63
+
64
+ #6. ~~~ Get the data ~~~
65
  code = """
66
  print("Hello World!")
67
  """
 
69
  "language": "Python",
70
  "code": code,
71
  }
72
+
73
+ input_message = proxy_flow.package_input_message(input_data)
74
+
75
+ #7. ~~~ Run inference ~~~
76
+ future = proxy_flow.get_reply_future(input_message)
77
+
78
+ #uncomment this line if you would like to get the full message back
79
+ #reply_message = future.get_message()
80
+ reply_data = future.get_data()
81
+
82
+ # ~~~ Print the output ~~~
83
+ print("~~~~~~Reply~~~~~~")
84
+ print(reply_data)
85
+
86
+
87
+ #8. ~~~~ (Optional) apply output interface on reply ~~~~
88
+ # output_interface = KeyInterface(
89
+ # keys_to_rename={"api_output": "answer"},
90
+ # )
91
+ # print("Output: ", output_interface(reply_data))
92
+
93
+
94
+ #9. ~~~~~Optional: Unserve Flow~~~~~~
95
+ # serve_utils.delete_served_flow(cl, "FlowModule")
96
+
97