Skip to content

Commit d2c160d

Browse files
committed
make sampling work
1 parent 70c4f3a commit d2c160d

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

src/db/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ export class DB {
447447
`)
448448

449449
const insertResult = await ps
450-
.bind(validatedTag.name, validatedTag.description, userId)
450+
.bind(validatedTag.name, validatedTag.description ?? null, userId)
451451
.run()
452452

453453
if (!insertResult.success || !insertResult.meta.last_row_id) {

src/db/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const tagSchema = z.object({
7171

7272
export const newTagSchema = z.object({
7373
name: z.string(),
74-
description: z.string().nullable().optional(),
74+
description: z.string().optional(),
7575
})
7676

7777
export const entryTagSchema = z.object({

src/tools.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ Please ask them explicitely for their email address and don't just guess.
170170

171171
const existingTags = await agent.db.getTags(user.id)
172172
const existingTagNames = existingTags.map((t) => t.name)
173+
const currentTags = await agent.db.getEntryTags(
174+
user.id,
175+
createdEntry.id,
176+
)
177+
const currentTagNames = currentTags.map((t) => t.name)
173178

174179
const result = await agent.server.server.createMessage({
175180
messages: [
@@ -179,16 +184,24 @@ Please ask them explicitely for their email address and don't just guess.
179184
type: 'text',
180185
mimeType: 'text/plain',
181186
text: `
182-
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:
183-
Title: ${createdEntry.title}
184-
Content: ${createdEntry.content}
185-
Mood: ${createdEntry.mood || 'not specified'}
186-
Location: ${createdEntry.location || 'not specified'}
187-
Weather: ${createdEntry.weather || 'not specified'}
188-
189-
Existing tags: ${existingTagNames.join(', ')}
190-
191-
Respond with a JSON array of tag names only.
187+
Based on this journal entry, suggest relevant tags. Consider the title, content, mood, location, and weather. Only suggest tags that are not already applied to this entry. Feel free to suggest new tags that are not currently in the database and they will be created.
188+
189+
<entry
190+
id="${createdEntry.id}"
191+
title="${createdEntry.title}"
192+
mood="${createdEntry.mood || 'not specified'}"
193+
location="${createdEntry.location || 'not specified'}"
194+
weather="${createdEntry.weather || 'not specified'}"
195+
is-private="${createdEntry.isPrivate ? 'true' : 'false'}"
196+
is-favorite="${createdEntry.isFavorite ? 'true' : 'false'}"
197+
tags="${currentTagNames.join(', ')}"
198+
>
199+
${createdEntry.content}
200+
</entry>
201+
202+
Existing tags already in the database: ${existingTagNames.join(', ')}
203+
204+
Respond with a JSON array of tag names only. If you don't suggest any tags, respond with an empty array.
192205
`.trim(),
193206
},
194207
},
@@ -219,15 +232,17 @@ Respond with a JSON array of tag names only.
219232
for (const tagName of newTags) {
220233
await agent.db.createTag(user.id, { name: tagName })
221234
}
235+
}
222236

223-
const createdTags = await agent.db.getTags(user.id)
237+
const userTags = await agent.db.getTags(user.id)
224238

225-
for (const tag of createdTags) {
226-
await agent.db.addTagToEntry(user.id, {
227-
entryId: createdEntry.id,
228-
tagId: tag.id,
229-
})
230-
}
239+
for (const tag of userTags.filter((t) =>
240+
suggestedTags.includes(t.name),
241+
)) {
242+
await agent.db.addTagToEntry(user.id, {
243+
entryId: createdEntry.id,
244+
tagId: tag.id,
245+
})
231246
}
232247

233248
return createReply({

0 commit comments

Comments
 (0)