Skip to content

Commit 87374df

Browse files
committed
feat: add orchestrator_get_example
This commit add a way to get an example when the LLM needs to call it. Signed-off-by: Eloy Coto <eloy.coto@acalustra.com>
1 parent c474f6f commit 87374df

10 files changed

+425
-1
lines changed

tools/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
from .orchestrator_creation_workflow_rules import creation_workflow_rules
2+
from .orchestrator_get_sample_workflow import orchestrator_get_sample_workflow
23
from .orchestrator_workflow_renderer import orchestrator_preview_workflow
34

4-
__all__ = [creation_workflow_rules, orchestrator_preview_workflow]
5+
__all__ = [
6+
creation_workflow_rules,
7+
orchestrator_get_sample_workflow,
8+
orchestrator_preview_workflow,
9+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This example shows off the Switch State and the subflow action. The workflow is started with application information data as input
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
```json
3+
{
4+
"id": "applicantrequest",
5+
"version": "1.0",
6+
"specVersion": "0.8",
7+
"name": "Applicant Request Decision Workflow",
8+
"description": "Determine if applicant request is valid",
9+
"start": "CheckApplication",
10+
"functions": [
11+
{
12+
"name": "sendRejectionEmailFunction",
13+
"operation": "http://myapis.org/applicationapi.json#emailRejection"
14+
}
15+
],
16+
"states":[
17+
{
18+
"name":"CheckApplication",
19+
"type":"switch",
20+
"dataConditions": [
21+
{
22+
"condition": "${ .applicants | .age >= 18 }",
23+
"transition": "StartApplication"
24+
},
25+
{
26+
"condition": "${ .applicants | .age < 18 }",
27+
"transition": "RejectApplication"
28+
}
29+
],
30+
"defaultCondition": {
31+
"transition": "RejectApplication"
32+
}
33+
},
34+
{
35+
"name": "StartApplication",
36+
"type": "operation",
37+
"actions": [
38+
{
39+
"subFlowRef": "startApplicationWorkflowId"
40+
}
41+
],
42+
"end": true
43+
},
44+
{
45+
"name":"RejectApplication",
46+
"type":"operation",
47+
"actionMode":"sequential",
48+
"actions":[
49+
{
50+
"functionRef": {
51+
"refName": "sendRejectionEmailFunction",
52+
"arguments": {
53+
"applicant": "${ .applicant }"
54+
}
55+
}
56+
}
57+
],
58+
"end": true
59+
}
60+
]
61+
}
62+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Gpenerate a serverless workflow which:
2+
- Obtain the public IP info from http://ipinfo.io/json
3+
- If the request is 404, please log the error.
4+
- If the request is sucessfull make an http request to https://httpbin.org/post which the payload from previous request with city and public ip
5+
- Log all the final state variable in the logs on log level INFO
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
```json
2+
{
3+
"id": "get_public_info",
4+
"name": "Get And publish ip information",
5+
"version": "1.0",
6+
"specVersion": "0.8",
7+
"start": "Get public IP",
8+
"errors": [
9+
{
10+
"name": "notAvailable",
11+
"code": "404"
12+
}
13+
],
14+
"functions": [
15+
{
16+
"name": "getIP",
17+
"type": "custom",
18+
"operation": "rest:get:https://ipinfo.io/json"
19+
},
20+
{
21+
"name": "pushData",
22+
"type": "custom",
23+
"operation": "rest:post:https://httpbin.org/post"
24+
},
25+
{
26+
"name": "logInfo",
27+
"type": "custom",
28+
"operation": "sysout:INFO"
29+
}
30+
],
31+
"states": [
32+
{
33+
"name": "Get public IP",
34+
"type": "operation",
35+
"actions": [
36+
{
37+
"functionRef": {
38+
"refName": "getIP"
39+
},
40+
"actionDataFilter": {
41+
"toStateData": ".ip_info"
42+
}
43+
}
44+
],
45+
"onErrors": [
46+
{
47+
"errorRef": "notAvailable",
48+
"transition": "logError"
49+
}
50+
],
51+
"transition": "push_host_data"
52+
},
53+
{
54+
"name": "push_host_data",
55+
"type": "operation",
56+
"actions": [
57+
{
58+
"functionRef": {
59+
"refName": "pushData",
60+
"arguments": {
61+
"city": ".ip_info.city",
62+
"ip": ".ip_info.ip"
63+
}
64+
},
65+
"actionDataFilter": {
66+
"toStateData": ".results"
67+
}
68+
}
69+
],
70+
"onErrors": [
71+
{
72+
"errorRef": "notAvailable",
73+
"transition": "logError"
74+
}
75+
],
76+
"transition": "finalState"
77+
},
78+
{
79+
"name": "finalState",
80+
"type": "operation",
81+
"actions": [
82+
{
83+
"functionRef": {
84+
"refName": "logInfo",
85+
"arguments": {
86+
"message": "\"FINAL INFORMATION!: \\(.)\""
87+
}
88+
}
89+
}
90+
],
91+
"end": true
92+
},
93+
{
94+
"name": "logError",
95+
"type": "operation",
96+
"actions": [
97+
{
98+
"functionRef": {
99+
"refName": "logInfo",
100+
"arguments": {
101+
"message": "\"GOT 404 message, state value=\\(.)\""
102+
}
103+
}
104+
}
105+
],
106+
"end": true
107+
}
108+
]
109+
}
110+
```

tools/examples/iteration_input.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
I need to generate a workflow wich track room temperature for different rooms on my building.
2+
3+
The workflow should have an input with multiple rooms, in json array, like:
4+
5+
```
6+
{"rooms": ["kitchen", "bedroom1", "bathroom"]}
7+
```
8+
9+
for each room, you need to iterate over the array and make an http request to http://office-status.local/temperature/$ROOM. When you made all request, please create a json like
10+
11+
```
12+
[
13+
{ "room": "kitchen", "temperature": 23 },
14+
{ "room": "bedroom1", "temperature": 18 },
15+
{ "room": "bathroom", "temperature": 18 }
16+
]
17+
```
18+
19+
This json need to be posted into http://erp.local/roomTemperatures, using a POST request and all rooms information should be in a json object, with the key .rooms
20+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Here you have the workflow:
2+
3+
```json
4+
{
5+
"id": "getTemperature",
6+
"name": "Get temperature by room",
7+
"version": "1.0",
8+
"specVersion": "0.8",
9+
"start": "getAllRoomTemperature",
10+
"functions": [
11+
{
12+
"name": "getRoomTemperature",
13+
"type": "custom",
14+
"operation": "rest:get:http://office-status.local/temperature/{room_name}"
15+
},
16+
{
17+
"name": "reportInfo",
18+
"type": "custom",
19+
"operation": "rest:post:http://erp.local/roomTemperatures"
20+
}
21+
],
22+
"states": [
23+
{
24+
"name": "getAllRoomTemperature",
25+
"type": "foreach",
26+
"inputCollection": "${ .rooms }",
27+
"outputCollection": "${ .results }",
28+
"iterationParam": "roomName",
29+
"actions": [
30+
{
31+
"functionRef": {
32+
"refName": "getRoomTemperature",
33+
"arguments": {
34+
"room_name": "${ .roomName }"
35+
}
36+
},
37+
"actionDataFilter": {
38+
"results": "{room: .roomName, temperature:.temperature}"
39+
}
40+
}
41+
],
42+
"transition": "reportInfo"
43+
},
44+
{
45+
"name": "reportInfo",
46+
"type": "operation",
47+
"actions": [
48+
{
49+
"functionRef": {
50+
"refName": "reportInfo",
51+
"arguments": {
52+
"rooms": "${ .results }"
53+
}
54+
},
55+
"actionDataFilter": {
56+
"toStateData": ".reportInformation"
57+
}
58+
}
59+
],
60+
"end": true
61+
}
62+
]
63+
}
64+
```
65+
66+
Key points for this workflow:
67+
68+
- *Functions*: Two functions are created:
69+
- `getRoomTemperature` which uses your url and has an argument `room_name`
70+
- `reportInfo` which POST the information to the given url.
71+
- *States*:
72+
- `getAllRoomTemperature`:
73+
- I assume that the input of rooms will be part of the object when calling the worklow, under "rooms" field. The state iterate over each entry of the array and get information using the `getRoomTemperature` function.
74+
- To create a valid information for the next stage, the output is filtered and prepared in the actionDataFilter action with the roomName and the temperature.
75+
- When finished, the workflow will call the `reportInfo` state.
76+
- `reportInfo`:
77+
- It'll use the reportInfo function, because it's already defined.
78+
- It'll create an argument which will be posted with the rooms key
79+
- It'll return the report information under the `.reportInformation` key
80+
- Because the workflow does not have more steps, set end:true
81+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In this example we show the use of scheduled cron-based start event property. The example workflow checks the users inbox every 15 minutes and send them a text message when there are important emails.
2+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
```json
2+
{
3+
"id": "checkInbox",
4+
"name": "Check Inbox Workflow",
5+
"version": "1.0",
6+
"specVersion": "0.8",
7+
"description": "Periodically Check Inbox",
8+
"start": {
9+
"stateName": "CheckInbox",
10+
"schedule": {
11+
"cron": "0 0/15 * * * ?"
12+
}
13+
},
14+
"functions": [
15+
{
16+
"name": "checkInboxFunction",
17+
"operation": "http://myapis.org/inboxapi.json#checkNewMessages"
18+
},
19+
{
20+
"name": "sendTextFunction",
21+
"operation": "http://myapis.org/inboxapi.json#sendText"
22+
}
23+
],
24+
"states": [
25+
{
26+
"name": "CheckInbox",
27+
"type": "operation",
28+
"actionMode": "sequential",
29+
"actions": [
30+
{
31+
"functionRef": "checkInboxFunction"
32+
}
33+
],
34+
"transition": "SendTextForHighPriority"
35+
},
36+
{
37+
"name": "SendTextForHighPriority",
38+
"type": "foreach",
39+
"inputCollection": "${ .messages }",
40+
"iterationParam": "singlemessage",
41+
"actions": [
42+
{
43+
"functionRef": {
44+
"refName": "sendTextFunction",
45+
"arguments": {
46+
"message": "${ .singlemessage }"
47+
}
48+
}
49+
}
50+
],
51+
"end": true
52+
}
53+
]
54+
}
55+
```

0 commit comments

Comments
 (0)