Skip to content

Commit

Permalink
feat(api/folders): remove minimum results
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Nov 8, 2024
1 parent 9eeafa5 commit 6b9dff0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions web/app/api/(newai)/folders/v2/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ export async function POST(request: NextRequest) {
const response = await generateObject({
model,
schema: z.object({
suggestedFolders: z.array(z.object({
score: z.number().min(0).max(100),
isNewFolder: z.boolean(),
folder: z.string(),
reason: z.string(),
})).min(3)
suggestedFolders: z
.array(
z.object({
score: z.number().min(0).max(100),
isNewFolder: z.boolean(),
folder: z.string(),
reason: z.string(),
})
)
.max(5),
}),
system: `Given the content and (if useful) the file name: "${fileName}", suggest relevant folders from the following list: ${folders.join(
", if none of the folders are relevant, suggest new folders"
Expand All @@ -35,7 +39,9 @@ export async function POST(request: NextRequest) {
console.log("incrementing token usage folders", userId, tokens);
await incrementAndLogTokenUsage(userId, tokens);
return NextResponse.json({
folders: response.object.suggestedFolders.sort((a, b) => b.score - a.score),
folders: response.object.suggestedFolders.sort(
(a, b) => b.score - a.score
),
});
} catch (error) {
if (error) {
Expand Down

0 comments on commit 6b9dff0

Please sign in to comment.