You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on this journal entry, suggest relevant tags. Consider the title, content, mood, location, and weather. Only suggest tags that don't already exist. Here's the entry:
'You are a helpful assistant that suggests relevant tags for journal entries. Only suggest tags that would be useful for categorizing and finding entries later. Respond with a JSON array of tag names only.',
198
+
maxTokens: 1000,
199
+
})
200
+
201
+
constresponseSchema=z.object({
202
+
content: z.object({
203
+
type: z.literal('text'),
204
+
text: z
205
+
.string()
206
+
.transform((text)=>
207
+
z.array(z.string()).parse(JSON.parse(text)),
208
+
),
209
+
}),
210
+
})
211
+
constparsedResult=responseSchema.parse(result)
212
+
constsuggestedTags=parsedResult.content.text
213
+
214
+
constnewTags=suggestedTags.filter(
215
+
(tag: string)=>!existingTagNames.includes(tag),
168
216
)
217
+
218
+
if(newTags.length>0){
219
+
for(consttagNameofnewTags){
220
+
awaitagent.db.createTag(user.id,{name: tagName})
221
+
}
222
+
223
+
constcreatedTags=awaitagent.db.getTags(user.id)
224
+
225
+
for(consttagofcreatedTags){
226
+
awaitagent.db.addTagToEntry(user.id,{
227
+
entryId: createdEntry.id,
228
+
tagId: tag.id,
229
+
})
230
+
}
231
+
}
232
+
233
+
returncreateReply({
234
+
entry: `Entry "${createdEntry.title}" created successfully with ID "${createdEntry.id}"`,
235
+
suggestedTags: newTags,
236
+
message:
237
+
newTags.length>0
238
+
? `Here are some suggested tags for your entry: ${newTags.join(', ')}`
0 commit comments