feat: migrate to claude sonnet 4 (#4)
Some checks failed
Node.js CI / Lint and Test (push) Successful in 1m0s
Code Analysis / SonarQube (push) Failing after 1m14s

### Explanation

_No response_

### Issue

_No response_

### Attestations

- [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/)
- [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/).
- [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/).

### Dependencies

- [ ] I have pinned the dependencies to a specific patch version.

### Style

- [ ] I have run the linter and resolved any errors.
- [ ] My pull request uses an appropriate title, matching the conventional commit standards.
- [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request.

### Tests

- [ ] My contribution adds new code, and I have added tests to cover it.
- [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes.
- [ ] All new and existing tests pass locally with my changes.
- [ ] Code coverage remains at or above the configured threshold.

### Documentation

_No response_

### Versioning

_No response_

Reviewed-on: #4
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit is contained in:
Naomi Carrigan 2025-05-22 11:15:33 -07:00 committed by Naomi Carrigan
parent 61f4fa05c6
commit 14f9d5b4d0
8 changed files with 250 additions and 385 deletions

View File

@ -14,16 +14,16 @@
"author": "Naomi Carrigan",
"license": "See license in LICENSE.md",
"devDependencies": {
"@nhcarrigan/eslint-config": "5.1.0",
"@nhcarrigan/eslint-config": "5.2.0",
"@nhcarrigan/typescript-config": "4.0.0",
"@types/node": "22.13.1",
"eslint": "9.20.0",
"typescript": "5.7.3"
"@types/node": "22.15.21",
"eslint": "9.27.0",
"typescript": "5.8.3"
},
"dependencies": {
"@anthropic-ai/sdk": "0.36.3",
"@anthropic-ai/sdk": "0.52.0",
"@nhcarrigan/logger": "1.0.0",
"discord.js": "14.18.0",
"fastify": "5.2.1"
"discord.js": "14.19.3",
"fastify": "5.3.3"
}
}

605
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,11 @@ import { calculateCost } from "../utils/calculateCost.js";
import { isSubscribed } from "../utils/isSubscribed.js";
import { logger } from "../utils/logger.js";
import { replyToError } from "../utils/replyToError.js";
import type { ImageBlockParam } from "@anthropic-ai/sdk/resources/index.js";
import type { Base64ImageSource } from "@anthropic-ai/sdk/resources/index.js";
const isValidContentType = (
type: string,
): type is ImageBlockParam["source"]["media_type"] => {
): type is Base64ImageSource["media_type"] => {
return [
"image/jpg",
"image/jpeg",
@ -100,7 +100,7 @@ export const alt = async(
role: "user",
},
],
model: "claude-3-5-sonnet-latest",
model: "claude-sonnet-4-20250514",
system: `${personality} Your role in this conversation is to generate descriptive and accessible alt-text for the user's image. Be as descriptive as possible. Do not include ANYTHING in your response EXCEPT the actual alt-text. Wrap the text in a multi-line code block for easy copying.`,
temperature: 1,
});

View File

@ -31,7 +31,7 @@ export const evaluate = async(
// eslint-disable-next-line @typescript-eslint/naming-convention -- Required key format for SDK.
max_tokens: 2000,
messages: [ { content: code, role: "user" } ],
model: "claude-3-5-sonnet-latest",
model: "claude-sonnet-4-20250514",
system: `${personality} Your role in this conversation is to evaluate the user's code and provide the result. Wrap ONLY THE CODE RESULT in a multi-line code block for easy copying.`,
temperature: 1,
});

View File

@ -32,7 +32,7 @@ export const mood = async(
// eslint-disable-next-line @typescript-eslint/naming-convention -- Required key format for SDK.
max_tokens: 2000,
messages: [ { content: prompt, role: "user" } ],
model: "claude-3-5-sonnet-latest",
model: "claude-sonnet-4-20250514",
system: `${personality} Your role in this conversation is to analyse the text the user provides for the overall sentiment and mood of the author.`,
temperature: 1,
});

View File

@ -32,7 +32,7 @@ export const proofread = async(
// eslint-disable-next-line @typescript-eslint/naming-convention -- Required key format for SDK.
max_tokens: 2000,
messages: [ { content: prompt, role: "user" } ],
model: "claude-3-5-sonnet-latest",
model: "claude-sonnet-4-20250514",
system: `${personality} Your role in this conversation is to proofread the text the user has provided. You should identify spelling and grammatical errors using British English.`,
temperature: 1,
});

View File

@ -32,7 +32,7 @@ export const query = async(
// eslint-disable-next-line @typescript-eslint/naming-convention -- Required key format for SDK.
max_tokens: 2000,
messages: [ { content: prompt, role: "user" } ],
model: "claude-3-5-sonnet-latest",
model: "claude-sonnet-4-20250514",
system: `${personality} Your role in this conversation is to answer the user's question to the best of your abilities. When possible, include links to relevant sources.`,
temperature: 1,
});

View File

@ -32,7 +32,7 @@ export const summarise = async(
// eslint-disable-next-line @typescript-eslint/naming-convention -- Required key format for SDK.
max_tokens: 2000,
messages: [ { content: prompt, role: "user" } ],
model: "claude-3-5-sonnet-latest",
model: "claude-sonnet-4-20250514",
system: `${personality} Your role in this conversation is to summarise the text the user has provided. Your goal is to reach 250 words or less. Wrap ONLY THE SUMMARY in multi-line code block so it is easy to copy.`,
temperature: 1,
});