workflow_util.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2025 AIDC-AI
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. Workflow Path Resolver
  14. Standardized workflow path resolution for all ComfyUI services.
  15. Convention: {source}/{service}.json
  16. Examples:
  17. - Image analysis: selfhost/analyse_image.json, runninghub/analyse_image.json
  18. - Image generation: selfhost/image.json, runninghub/image.json
  19. - Video generation: selfhost/video.json, runninghub/video.json
  20. - TTS: selfhost/tts.json, runninghub/tts.json
  21. """
  22. from typing import Literal
  23. WorkflowSource = Literal['runninghub', 'selfhost']
  24. def resolve_workflow_path(
  25. service_name: str,
  26. source: WorkflowSource = 'runninghub'
  27. ) -> str:
  28. """
  29. Resolve workflow path using standardized naming convention
  30. Convention: workflows/{source}/{service_name}.json
  31. Args:
  32. service_name: Service identifier (e.g., "analyse_image", "image", "video", "tts")
  33. source: Workflow source - 'runninghub' (default) or 'selfhost'
  34. Returns:
  35. Workflow path in format: "{source}/{service_name}.json"
  36. Examples:
  37. >>> resolve_workflow_path("analyse_image", "runninghub")
  38. 'runninghub/analyse_image.json'
  39. >>> resolve_workflow_path("analyse_image", "selfhost")
  40. 'selfhost/analyse_image.json'
  41. >>> resolve_workflow_path("image") # defaults to runninghub
  42. 'runninghub/image.json'
  43. """
  44. return f"{source}/{service_name}.json"
  45. def get_default_source() -> WorkflowSource:
  46. """
  47. Get default workflow source
  48. Returns:
  49. 'runninghub' - Cloud-first approach, better for beginners
  50. """
  51. return 'runninghub'