-
Notifications
You must be signed in to change notification settings - Fork 8
/
asl.json
125 lines (125 loc) · 3.73 KB
/
asl.json
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
{
"Comment": "Máquina de estados que lê mensagens do DynamoDB, processa com o Amazon Bedrock e encadeia as respostas, truncando o histórico da conversa usando uma função Lambda.",
"StartAt": "Seed the DynamoDB Table",
"TimeoutSeconds": 3600,
"States": {
"Seed the DynamoDB Table": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "MyLambdaFunction"
},
"ResultPath": "$.List",
"Next": "Initialize Conversation History"
},
"Initialize Conversation History": {
"Type": "Pass",
"Result": "",
"ResultPath": "$.ConversationHistory",
"Next": "For Loop Condition"
},
"For Loop Condition": {
"Type": "Choice",
"Choices": [
{
"Not": {
"Variable": "$.List[0]",
"StringEquals": "DONE"
},
"Next": "Read Next Message from DynamoDB"
}
],
"Default": "Succeed"
},
"Read Next Message from DynamoDB": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:getItem",
"Parameters": {
"TableName": "<NOME_DA_TABELA_DYNAMODB>",
"Key": {
"MessageId": {
"S.$": "$.List[0]"
}
}
},
"ResultPath": "$.DynamoDB",
"Next": "Update Conversation History with Message"
},
"Update Conversation History with Message": {
"Type": "Pass",
"Parameters": {
"ConversationHistory.$": "States.Format('{}\n{}', $.ConversationHistory, $.DynamoDB.Item.Message.S)"
},
"ResultPath": "$.ConversationHistory",
"Next": "Truncate Conversation History"
},
"Truncate Conversation History": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "TruncateHistoryFunction",
"Payload": {
"ConversationHistory.$": "$.ConversationHistory",
"MaxLength": 2000
}
},
"ResultSelector": {
"ConversationHistory.$": "$.Payload.ConversationHistory"
},
"ResultPath": "$.ConversationHistory",
"Next": "Invoke Model with Message"
},
"Invoke Model with Message": {
"Type": "Task",
"Resource": "arn:aws:states:::bedrock:invokeModel",
"Parameters": {
"ModelId": "cohere.command-text-v14",
"Body": {
"prompt.$": "$.ConversationHistory",
"max_tokens": 250
},
"ContentType": "application/json",
"Accept": "*/*"
},
"ResultSelector": {
"ModelResponse.$": "$.Body.generations[0].text"
},
"ResultPath": "$.ModelResult",
"Next": "Update Conversation History with Response"
},
"Update Conversation History with Response": {
"Type": "Pass",
"Parameters": {
"ConversationHistory.$": "States.Format('{}\n{}', $.ConversationHistory, $.ModelResult.ModelResponse)"
},
"ResultPath": "$.ConversationHistory",
"Next": "Truncate Conversation History After Response"
},
"Truncate Conversation History After Response": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "TruncateHistoryFunction",
"Payload": {
"ConversationHistory.$": "$.ConversationHistory",
"MaxLength": 2000
}
},
"ResultSelector": {
"ConversationHistory.$": "$.Payload.ConversationHistory"
},
"ResultPath": "$.ConversationHistory",
"Next": "Pop Element from List"
},
"Pop Element from List": {
"Type": "Pass",
"Parameters": {
"List.$": "$.List[1:]"
},
"Next": "For Loop Condition"
},
"Succeed": {
"Type": "Succeed"
}
}
}