-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontrol_flow_advanced.yaml
More file actions
222 lines (192 loc) · 6.86 KB
/
control_flow_advanced.yaml
File metadata and controls
222 lines (192 loc) · 6.86 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
id: control-flow-advanced
# Advanced Control Flow Example
# Combines conditionals and loops in a practical scenario
name: Multi-Stage Text Processing
description: Process text through multiple stages with conditional paths
version: "1.0.0"
parameters:
input_text:
type: string
description: Text to process
default: "This is a sample text for processing."
languages:
type: array
default: ["es", "fr", "de"]
description: Languages to translate to
quality_threshold:
type: number
default: 0.7
description: Quality threshold for translations
output:
type: string
default: "examples/outputs/control_flow_advanced"
description: Output directory for results
steps:
# Initial analysis
- id: analyze_text
action: analyze_text
parameters:
text: "{{ input_text }}"
model: "ollama:llama3.2:1b"
analysis_type: "comprehensive"
# Determine if text needs enhancement
- id: check_quality
action: generate_text
parameters:
prompt: |
Based on this text analysis, determine if the text quality is below {{ quality_threshold }} (out of 1.0) and needs improvement:
Analysis: {{ analyze_text }}
Respond with either "improve" or "acceptable" based on the quality assessment.
model: "ollama:llama3.2:1b"
max_tokens: 50
dependencies:
- analyze_text
# Conditional enhancement
- id: enhance_text
action: generate_text
if: "{{ 'improve' in check_quality }}"
parameters:
prompt: |
Improve the following text to make it clearer and more professional. Output ONLY the improved version, no explanations:
Original text: {{ input_text }}
model: "ollama:llama3.2:1b"
max_tokens: 500
dependencies:
- check_quality
# Determine which text to use (creates a concrete value we can reference)
- id: select_text
action: generate_text
parameters:
prompt: |
{% if check_quality and 'improve' in check_quality and enhance_text %}
Output ONLY this text without any changes or additions:
{{ enhance_text }}
{% else %}
Output ONLY this text without any changes or additions:
{{ input_text }}
{% endif %}
model: "ollama:llama3.2:1b"
max_tokens: 600
dependencies:
- enhance_text
- check_quality
# Translate to multiple languages
- id: translate_text
for_each: "{{ languages }}"
max_parallel: 2
steps:
# Translate
- id: translate
action: generate_text
parameters:
prompt: |
Translate the following text to {{ $item }}. Provide ONLY the direct translation, no explanations or commentary:
Text to translate: "{{ input_text }}"
model: "ollama:llama3.2:1b"
max_tokens: 600
# Validate translation quality
- id: validate_translation
action: generate_text
parameters:
prompt: |
Assess the quality of this translation from English to {{ $item }}:
Original English: "{{ input_text }}"
Translation: "{{ translate }}"
Evaluate the translation for:
1. Accuracy - Does it convey the same meaning as the original?
2. Fluency - Is it natural and grammatically correct in {{ $item }}?
3. Completeness - Are all concepts from the original included?
Provide a brief quality assessment and rate it as: excellent, good, acceptable, or poor.
model: "ollama:llama3.2:1b"
max_tokens: 1500
dependencies:
- translate
# Save translation
- id: save_translation
tool: filesystem
action: write
parameters:
path: "{{ output }}/translations/{{ input_text[:50] | slugify }}_{{ $item }}.md"
content: |
# Translation to {{ item | upper }}
## Original Text
{{ input_text }}
## Translated Text
{{ translate }}
## Translation Quality Assessment
{{ validate_translation }}
dependencies:
- validate_translation
dependencies:
- select_text
# Example of multiple conditionals: Create different summary types
- id: create_brief_summary
action: generate_text
if: "{{ languages | length <= 2 }}"
parameters:
prompt: |
Create a brief summary of the translation process.
Original text: {{ input_text }}
Languages: {{ languages }}
model: "ollama:llama3.2:1b"
max_tokens: 100
dependencies:
- translate_text
- id: create_detailed_summary
action: generate_text
if: "{{ languages | length > 2 }}"
parameters:
prompt: |
Create a detailed summary of the multi-language translation process.
Original text: {{ input_text }}
Languages: {{ languages }}
Analysis: {{ analyze_text }}
model: "ollama:llama3.2:1b"
max_tokens: 200
dependencies:
- translate_text
# Example of aggregation: Count successful operations
- id: check_translation_count
action: generate_text
parameters:
prompt: |
Count how many languages were successfully translated.
Languages attempted: {{ languages }}
Brief summary: {{ create_brief_summary | default('N/A') }}
Detailed summary: {{ create_detailed_summary | default('N/A') }}
Return just a number.
model: "ollama:llama3.2:1b"
max_tokens: 10
dependencies:
- create_brief_summary
- create_detailed_summary
# Create final report
- id: create_report
tool: filesystem
action: write
parameters:
path: "{{ output }}/{{ input_text[:50] | slugify }}_report.md"
content: |
# Multi-Stage Text Processing Report
## Original Text
{{ input_text }}
## Analysis
{{ analyze_text }}
## Quality Check Result
{{ check_quality }}
## Enhancement Status
{% if enhance_text %}Enhanced version was created{% else %}Original text was sufficient{% endif %}
## Final Text Used for Translation
{% if select_text %}{{ select_text }}{% else %}{{ input_text }}{% endif %}
## Translations
Attempted translations to: {{ languages | join(', ') }}
Check the {{ output }}/translations/ directory for successful translations.
dependencies:
- translate_text
outputs:
analysis: "{{ analyze_text }}"
quality_check: "{{ check_quality }}"
enhanced: "{{ enhance_text | default('N/A') }}"
final_text: "{{ select_text }}"
translation_count: "{{ check_translation_count }}"
report_file: "{{ output }}/{{ input_text[:50] | slugify }}_report.md"