Skip to content

Commit 081a525

Browse files
committed
upgrade to sonnet 4.6, refactor to streamText + Output.object
1 parent 026aa8d commit 081a525

6 files changed

Lines changed: 54 additions & 42 deletions

File tree

apps/web/app/api/ai/support-chat/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const POST = withSession(async ({ req, session }) => {
5151
}
5252

5353
const result = streamText({
54-
model: anthropic("claude-sonnet-4-20250514"),
54+
model: anthropic("claude-sonnet-4-6"),
5555
system: buildSystemPrompt(globalContext),
5656
messages: await convertToModelMessages(messages),
5757
stopWhen: stepCountIs(5),

apps/web/lib/actions/partners/generate-lander.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import FireCrawlApp, {
1616
ErrorResponse,
1717
ScrapeResponse,
1818
} from "@mendable/firecrawl-js";
19-
import { generateObject } from "ai";
19+
import { generateText, Output } from "ai";
2020
import * as z from "zod/v4";
2121
import { authActionClient } from "../safe-action";
2222
import { throwIfNoPermission } from "../throw-if-no-permission";
@@ -95,9 +95,11 @@ export const generateLanderAction = authActionClient
9595
? cleanMarkdown(pricingScrapeResult.markdown || "")
9696
: null;
9797

98-
const { object } = await generateObject({
99-
model: anthropic("claude-sonnet-4-20250514"),
100-
schema: landerData ? programLanderSchema : programLanderSimpleSchema,
98+
const { output } = await generateText({
99+
model: anthropic("claude-sonnet-4-6"),
100+
output: Output.object({
101+
schema: landerData ? programLanderSchema : programLanderSimpleSchema,
102+
}),
101103
prompt:
102104
// Instructions
103105
`Generate a basic landing page for an affiliate program powered by Dub Partners based on a company website. ` +
@@ -137,7 +139,7 @@ export const generateLanderAction = authActionClient
137139
temperature: 0.4,
138140
});
139141

140-
return programLanderSchema.parse(object);
142+
return programLanderSchema.parse(output);
141143
});
142144

143145
function cleanMarkdown(markdown: string) {

apps/web/lib/ai/generate-csv-mapping.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { anthropic } from "@ai-sdk/anthropic";
44
import { createStreamableValue } from "@ai-sdk/rsc";
5-
import { streamObject } from "ai";
5+
import { Output, streamText } from "ai";
66
import * as z from "zod/v4";
77

88
export async function generateCsvMapping(
@@ -12,29 +12,33 @@ export async function generateCsvMapping(
1212
const stream = createStreamableValue();
1313

1414
(async () => {
15-
const { partialObjectStream } = streamObject({
16-
model: anthropic("claude-sonnet-4-20250514"),
17-
schema: z.object({
18-
link: z
19-
.string()
20-
.optional()
21-
.describe("The shortlink (link), including the domain and path."),
22-
url: z.string().optional().describe("The full URL of the shortlink"),
23-
title: z.string().optional().describe("The title of the shortlink"),
24-
description: z
25-
.string()
26-
.optional()
27-
.describe("The description of the shortlink"),
28-
tags: z
29-
.string()
30-
.optional()
31-
.describe(
32-
"A comma-separated list of tags for shortlink organization (NOT to be mapped to a description).",
33-
),
34-
createdAt: z
35-
.string()
36-
.optional()
37-
.describe("The date and time the shortlink was created (createdAt)"),
15+
const { partialOutputStream } = streamText({
16+
model: anthropic("claude-sonnet-6"),
17+
output: Output.object({
18+
schema: z.object({
19+
link: z
20+
.string()
21+
.optional()
22+
.describe("The shortlink (link), including the domain and path."),
23+
url: z.string().optional().describe("The full URL of the shortlink"),
24+
title: z.string().optional().describe("The title of the shortlink"),
25+
description: z
26+
.string()
27+
.optional()
28+
.describe("The description of the shortlink"),
29+
tags: z
30+
.string()
31+
.optional()
32+
.describe(
33+
"A comma-separated list of tags for shortlink organization (NOT to be mapped to a description).",
34+
),
35+
createdAt: z
36+
.string()
37+
.optional()
38+
.describe(
39+
"The date and time the shortlink was created (createdAt)",
40+
),
41+
}),
3842
}),
3943
prompt:
4044
`The following columns are the headings from a CSV import file for importing a company's short links. ` +
@@ -47,7 +51,7 @@ export async function generateCsvMapping(
4751
temperature: 0.2,
4852
});
4953

50-
for await (const partialObject of partialObjectStream) {
54+
for await (const partialObject of partialOutputStream) {
5155
stream.update(partialObject);
5256
}
5357

apps/web/lib/ai/generate-filters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function generateFilters(prompt: string) {
4242

4343
(async () => {
4444
const { partialOutputStream } = streamText({
45-
model: anthropic("claude-sonnet-4-20250514"),
45+
model: anthropic("claude-sonnet-6"),
4646
output: Output.object({ schema: AI_FILTER_SCHEMA }),
4747
system: SYSTEM_PROMPT,
4848
prompt,

apps/web/scripts/migrations/backfill-program-categories.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { anthropic } from "@ai-sdk/anthropic";
22
import { prisma } from "@dub/prisma";
33
import { Category } from "@dub/prisma/client";
44
import FireCrawlApp from "@mendable/firecrawl-js";
5-
import { generateObject } from "ai";
5+
import { generateText, Output } from "ai";
66
import "dotenv-flow/config";
77
import * as z from "zod/v4";
88

@@ -103,13 +103,16 @@ Page Title: ${title}
103103
Meta Description: ${description}
104104
Website Content Preview: ${content.slice(0, 300)}...`;
105105

106-
const { object } = await generateObject({
107-
model: anthropic("claude-sonnet-4-20250514"),
108-
schema: categorizationSchema,
106+
const { output } = await generateText({
107+
model: anthropic("claude-sonnet-4-6"),
108+
output: Output.object({
109+
schema: categorizationSchema,
110+
}),
109111
prompt,
112+
temperature: 0.4,
110113
});
111114

112-
return object.categories;
115+
return categorizationSchema.parse(output).categories;
113116
} catch (error) {
114117
// console.error(`Error categorizing ${programName}:`, error);
115118

apps/web/scripts/programs/add-to-marketplace.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { anthropic } from "@ai-sdk/anthropic";
22
import { prisma } from "@dub/prisma";
33
import { Category } from "@dub/prisma/client";
44
import FireCrawlApp from "@mendable/firecrawl-js";
5-
import { generateObject } from "ai";
5+
import { generateText, Output } from "ai";
66
import "dotenv-flow/config";
77
import * as z from "zod/v4";
88

@@ -94,13 +94,16 @@ Page Title: ${title}
9494
Meta Description: ${description}
9595
Website Content Preview: ${content.slice(0, 300)}...`;
9696

97-
const { object } = await generateObject({
98-
model: anthropic("claude-sonnet-4-20250514"),
99-
schema: categorizationSchema,
97+
const { output } = await generateText({
98+
model: anthropic("claude-sonnet-4-6"),
99+
output: Output.object({
100+
schema: categorizationSchema,
101+
}),
100102
prompt,
103+
temperature: 0.4,
101104
});
102105

103-
return object.categories;
106+
return categorizationSchema.parse(output).categories;
104107
} catch (error) {
105108
// console.error(`Error categorizing ${programName}:`, error);
106109

0 commit comments

Comments
 (0)