-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.yaml
179 lines (179 loc) · 6.27 KB
/
connect.yaml
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
input:
generate:
count: 1
mapping: |
root = {}
root.txn_id = uuid_v4()
root.product_id = "B07GVGTSLN"
root.product_name = "Samsung Galaxy S10E"
root.category = "Computers&Accessories"
root.discounted_price = "₹1,299"
root.actual_price = "₹1,299"
root.about_product = fake("paragraph")
root.user_id = "AEXK37TSBFHSP2TYE63YPKETWQ7Q"
root.user_name = "Avninder Singh"
pipeline:
processors:
- branch:
processors:
- ollama_embeddings:
model: mxbai-embed-large
text: |
Represent this sentence for searching relevant passages:
User ${!this.user_name} bought a product called ${!this.product_name},
which has the category ${!this.category} for ${!this.discounted_price}.
The product description is ${!this.about_product}
result_map: |
root.query_embedding = this
- branch:
processors:
- sql_raw:
driver: "clickhouse"
dsn: clickhouse://localhost:9000
query: |
SELECT * FROM sales
WHERE product_id != $1 AND user_id != $2
ORDER BY cosineDistance($3, text_embedding)
LIMIT 3
args_mapping: root = [ this.product_id, this.user_id, this.query_embedding ]
result_map: |
root.similar_products = this
- branch:
processors:
- ollama_chat:
model: llama3.2
max_tokens: 150
prompt: |
Your task is to generate a single email subject (nothing else)
for a customer who just bought a product called ${!this.product_name}
and is receiving a followup to entice them to come back to the store.
save_prompt_metadata: true
- ollama_moderation:
model: llama-guard3
prompt: "${!@prompt}"
response: "${!content()}"
result_map: |
root.email.subject = content().string()
root.email.subject_is_safe = @safe
- branch:
processors:
- ollama_chat:
model: llama3.2
prompt: |
A customer named ${!this.user_name} just bought a product called ${!this.product_name}.
Here are some similar products that other customers have recently bought:
${!this.similar_products.map_each(
product -> [product.product_name, product.about_product].join(" ")
).join("\n")}
Your task is to write a followup marketing email (the body only, no subject) to ${!this.user_name}
from Acme Corp (use the company name for the signature) that will thank them for their purchase
and give recommendations for them to come back based on the above similar products.
save_prompt_metadata: true
- log:
level: INFO
message: "PROMPT: ${!@prompt}"
- ollama_moderation:
model: llama-guard3
prompt: "${!@prompt}"
response: "${!content()}"
result_map: |
root.email.body = content().string()
root.email.body_is_safe = @safe
output:
broker:
outputs:
- http_client:
url: "https://api.mailslurp.com/emails"
headers:
Content-Type: application/json
x-api-key: "${API_KEY}"
processors:
- mapping: |
root.to = ["Test <[email protected]>"]
root.from = "Redpanda Connect <[email protected]>"
root.subject = this.email.subject.unquote().catch(this.email.subject)
root.body = this.email.body
root = if this.email.body_is_safe == "no" || this.email.subject_is_safe == "no" {
deleted()
}
- sql_insert:
driver: "clickhouse"
dsn: clickhouse://localhost:9000
table: llm_emails
init_statement: |
CREATE TABLE IF NOT EXISTS llm_emails (
txn_id TEXT,
subject TEXT,
subject_safe TEXT,
body TEXT,
body_safe TEXT
) ENGINE = MergeTree()
ORDER BY txn_id;
columns:
- txn_id
- subject
- subject_safe
- body
- body_safe
args_mapping: |
root = [
this.txn_id,
this.email.subject,
this.email.subject_is_safe,
this.email.body,
this.email.body_is_safe,
]
- processors:
- branch:
processors:
- ollama_embeddings:
model: mxbai-embed-large
text: |
User ${!this.user_name} bought a product called ${!this.product_name},
which has the category ${!this.category} for ${!this.discounted_price}.
The product description is ${!this.about_product}
They gave a review: ${!this.review_content}
result_map: |
root.text_embedding = this
sql_insert:
driver: "clickhouse"
dsn: clickhouse://localhost:9000
table: sales
columns:
- txn_id
- product_id
- product_name
- category
- discounted_price
- actual_price
- dicount_percentage
- rating
- rating_count
- about_product
- user_id
- user_name
- review_title
- review_content
- img_link
- product_link
- text_embedding
args_mapping: |
root = [
this.txn_id,
this.product_id,
this.product_name,
this.category,
this.discounted_price,
this.actual_price,
this.dicount_percentage,
this.rating,
this.rating_count,
this.about_product,
this.user_id,
this.user_name,
this.review_title,
this.review_content,
this.img_link,
this.product_link,
this.text_embedding,
]