-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow.py
More file actions
164 lines (142 loc) · 4.5 KB
/
Copy pathworkflow.py
File metadata and controls
164 lines (142 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import json
import yaml
from typing import Dict, Any, List
from node_types import *
class Workflow:
"""
Workflow class
"""
def __init__(self, name: str, nodes: List[CompleteNode], edges: List[CompleteEdge]):
"""
Initialize workflow
Args:
name: Workflow name
nodes: List of nodes
edges: List of edges
"""
self.name = name
self.nodes = nodes
self.edges = edges
def to_dict(self) -> Dict[str, Any]:
"""
Convert workflow to dictionary
Returns:
Workflow dictionary
"""
# Apply basic information (fixed template)
app_info = {
"description": "",
"icon": "🤖",
"icon_background": "#FFEAD5",
"mode": "workflow",
"name": self.name,
"use_icon_as_answer_icon": False
}
# Feature configuration (fixed template)
features = {
"file_upload": {
"allowed_file_extensions": [
".JPG",
".JPEG",
".PNG",
".GIF",
".WEBP",
".SVG"
],
"allowed_file_types": [
"image"
],
"allowed_file_upload_methods": [
"local_file",
"remote_url"
],
"enabled": False,
"fileUploadConfig": {
"audio_file_size_limit": 50,
"batch_count_limit": 5,
"file_size_limit": 15,
"image_file_size_limit": 10,
"video_file_size_limit": 100
},
"image": {
"enabled": False,
"number_limits": 3,
"transfer_methods": [
"local_file",
"remote_url"
]
},
"number_limits": 3
},
"opening_statement": "",
"retriever_resource": {
"enabled": True
},
"sensitive_word_avoidance": {
"enabled": False
},
"speech_to_text": {
"enabled": False
},
"suggested_questions": [],
"suggested_questions_after_answer": {
"enabled": False
},
"text_to_speech": {
"enabled": False,
"language": "",
"voice": ""
}
}
# View configuration (fixed template)
viewport = {
"x": 92.96659905656679,
"y": 79.13437154762897,
"zoom": 0.9002006986311041
}
# Nodes and edges
nodes_data = []
for node in self.nodes:
node_data = node.to_json()
nodes_data.append(node_data)
edges_data = []
for edge in self.edges:
edge_data = edge.to_json()
edges_data.append(edge_data)
# Build a complete workflow dictionary
workflow_dict = {
"app": app_info,
"kind": "app",
"version": "0.1.2",
"workflow": {
"conversation_variables": [],
"environment_variables": [],
"features": features,
"graph": {
"edges": edges_data,
"nodes": nodes_data,
"viewport": viewport
}
}
}
return workflow_dict
def save_to_yaml(self, file_path: str):
"""
Save workflow to YAML file
Args:
file_path: File path
"""
workflow_dict = self.to_dict()
with open(file_path, 'w', encoding='utf-8') as f:
yaml.dump(workflow_dict, f, allow_unicode=True, sort_keys=False)
print(f"Workflow saved to: {file_path}")
def save_to_json(self, file_path: str):
"""
Save workflow to JSON file
Args:
file_path: File path
"""
workflow_dict = self.to_dict()
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(workflow_dict, f, indent=2, ensure_ascii=False)
print(f"Workflow saved to: {file_path}")