Skip to content

Commit 840d5ee

Browse files
committed
feat: update teaser generation to use Opus 4.6 with adaptive thinking
Upgrade the Claude API call to use claude-opus-4-6 with adaptive thinking, a dedicated system prompt, and proper handling of thinking blocks in the response. Add evaluation script for manually reviewing generated teasers against recent articles.
1 parent 4a93bcc commit 840d5ee

4 files changed

Lines changed: 76 additions & 15 deletions

File tree

11ty/generate-teasers.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,26 @@ export function insertTeaserIntoFrontmatter(fileContent: string, teaser: string)
119119
return `${beforeClose}${formatTeaserYaml(teaser)}\n${afterClose}`
120120
}
121121

122-
async function generateTeaser(
122+
export async function generateTeaser(
123123
anthropic: Anthropic,
124124
title: string,
125125
content: string
126126
): Promise<string> {
127127
const message = await anthropic.messages.create({
128-
// Using claude-opus-4-5 alias to auto-update within Opus 4.5.x releases.
129-
// Anthropic provides 60 days notice before deprecation.
130-
// Check quarterly for new major versions: https://platform.claude.com/docs/en/about-claude/models/overview
131-
// Last checked: February 2026
132-
model: 'claude-opus-4-5',
133-
max_tokens: 300,
128+
model: 'claude-opus-4-6',
129+
max_tokens: 2048,
130+
thinking: { type: 'adaptive' },
131+
system: TEASER_PROMPT,
134132
messages: [
135133
{
136134
role: 'user',
137-
content: `${TEASER_PROMPT}\n\n---\n\nTitle: ${title}\n\n${content}`,
135+
content: `Title: ${title}\n\n${content}`,
138136
},
139137
],
140138
})
141139

142-
const block = message.content[0]
143-
if (block.type !== 'text') {
140+
const block = message.content.findLast((b) => b.type === 'text')
141+
if (!block || block.type !== 'text') {
144142
throw new Error('Unexpected response type from Anthropic API')
145143
}
146144

bin/evaluate-teasers.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import Anthropic from '@anthropic-ai/sdk'
2+
import { globby } from 'globby'
3+
import matter from 'gray-matter'
4+
import { readFile } from 'node:fs/promises'
5+
6+
import { generateTeaser } from '../11ty/generate-teasers.ts'
7+
8+
interface Article {
9+
title: string
10+
date: Date
11+
content: string
12+
}
13+
14+
async function main() {
15+
const count = parseInt(process.argv[2] ?? '5', 10)
16+
const anthropic = new Anthropic()
17+
const files = await globby('www/**/*.md')
18+
const articles: Article[] = []
19+
20+
for (const filePath of files) {
21+
const fileContent = await readFile(filePath, 'utf-8')
22+
const parsed = matter(fileContent)
23+
24+
const tags: string[] = parsed.data.tags ?? []
25+
if (!tags.includes('article')) continue
26+
27+
articles.push({
28+
title: parsed.data.title as string,
29+
date: new Date(parsed.data.date as string),
30+
content: parsed.content,
31+
})
32+
}
33+
34+
articles.sort((a, b) => b.date.getTime() - a.date.getTime())
35+
const latest = articles.slice(0, count)
36+
37+
console.log(`Evaluating teasers for ${latest.length} articles\n`)
38+
39+
for (const article of latest) {
40+
const preview = article.content.trim().slice(0, 500)
41+
42+
console.log('='.repeat(72))
43+
console.log(`Title: ${article.title}`)
44+
console.log(`Date: ${article.date.toISOString().slice(0, 10)}`)
45+
console.log('-'.repeat(72))
46+
console.log(preview)
47+
if (article.content.trim().length > 500) console.log('[...]')
48+
console.log('-'.repeat(72))
49+
50+
const teaser = await generateTeaser(anthropic, article.title, article.content)
51+
52+
console.log(`Teaser (${teaser.length} chars):`)
53+
console.log(teaser)
54+
console.log()
55+
}
56+
57+
console.log('Done.')
58+
}
59+
60+
main().catch((error: unknown) => {
61+
console.error(error)
62+
process.exit(1)
63+
})

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"typescript": "^5.9.3"
8585
},
8686
"devDependencies": {
87-
"@anthropic-ai/sdk": "^0.72.1",
87+
"@anthropic-ai/sdk": "^0.73.0",
8888
"@aws-sdk/client-cloudfront": "^3.859.0",
8989
"@dprint/formatter": "^0.4.1",
9090
"@types/aws-cloudfront-function": "^1.0.5",

0 commit comments

Comments
 (0)