-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
171 lines (164 loc) · 6.47 KB
/
main.py
File metadata and controls
171 lines (164 loc) · 6.47 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
from litellm.types.completion import ChatCompletionUserMessageParam
from src.orchestrator.prompt_orchestrator import PromptOrchestrator
from src.postprocessing.flow_post import flow_postprocessing
from src.schema.flow_type_schema import FlowType
from src.schema.flow_schema import Flow
from src.store.function_store import FunctionStore
if __name__ == '__main__':
# function store
function_store = FunctionStore()
function_store.insert_from_json("./test/functions.json", "./test/datatypes.json")
# orchestrator
prompt_orchestrator = PromptOrchestrator()
prompt = "Erstelle einen HTTP Event Flow, der zuerst den Request loggt und dann 'Event empfangen' an Slack sendet."
prompt_functions = function_store.search(
prompt=prompt,
limit=10
)
few_shots = [
ChatCompletionUserMessageParam(role="user", content="Erstelle einen Webhook flow, welche4 ein user objekt speichert und anschließend die mail als response zurückgibt."),
{
"role": "assistant",
"content": Flow(**{
"name": "User email webhook",
"nodes": [
{
"functionIdentifier": "std::control::value",
"id": 1,
"nextNodeId": 2,
"parameters": [
{
"value": {
"email": "test@test.com",
"username": "test",
}
}
],
},
{
"functionIdentifier": "http::response::create",
"id": 2,
"nextNodeId": 3,
"parameters": [
{
"value": 200
},
{
"value": {}
},
{
"nodeFunctionId": 1,
"referencePath": [{
"path": "email"
}]
}
],
},
{
"functionIdentifier": "rest::control::respond",
"id": 3,
"parameters": [
{
"nodeFunctionId": 2,
}
],
}
],
"startingNodeId": 1,
"type": "http_event_flow"
}).model_dump_json()
},
ChatCompletionUserMessageParam(role="user", content="Erstelle einen Webhook flow, welcher über die Liste [1,2,3] iteriert und jede Zahl mal zwei rechnet und das Eregbnis zurückgibt."),
{
"role": "assistant",
"content": Flow(**{
"name": "Map list webhook flow",
"nodes": [
{
"functionIdentifier": "std::list::map",
"id": 1,
"nextNodeId": 4,
"parameters": [
{
"value": [1, 2, 3]
},
{
"startingNodeId": 2
}
],
},
{
"functionIdentifier": "std::number::multiply",
"id": 2,
"nextNodeId": 3,
"parameters": [
{
"nodeFunctionId": 1,
"parameterIndex": 1,
"input_index": 0
},
{
"value": 2
}
],
},
{
"functionIdentifier": "std::control::return",
"id": 3,
"parameters": [
{
"nodeFunctionId": 2,
}
],
},
{
"functionIdentifier": "http::response::create",
"id": 4,
"nextNodeId": 5,
"parameters": [
{
"value": 200
},
{
"value": {}
},
{
"nodeFunctionId": 1,
}
],
},
{
"functionIdentifier": "rest::control::respond",
"id": 5,
"parameters": [
{
"nodeFunctionId": 4,
}
],
}
],
"startingNodeId": 1,
"type": "http_event_flow"
}).model_dump_json()
},
]
few_shot_functions = function_store.find_all(["std::control::value", "http::response::create", "rest::control::respond", "std::list::map", "std::control::return", "std::number::multiply"])
generated_flow = prompt_orchestrator.generate(
prompt=prompt,
few_shots=few_shots,
available_functions=function_store.combine(prompt_functions, few_shot_functions),
available_flow_types=[
FlowType(
identifier="http_event_flow",
names="HTTP Event Flow",
descriptions="Ein Flow, der durch HTTP-Events ausgelöst wird.",
signature="(): void",
)
],
)
print(flow_postprocessing(generated_flow, [FlowType(
identifier="http_event_flow",
names="HTTP Event Flow",
descriptions="Ein Flow, der durch HTTP-Events ausgelöst wird.",
signature="(): void",
)], function_store.get_all()).model_dump_json(indent=2, by_alias=True, exclude_none=True))