Skip to content

Commit 7cd7d93

Browse files
committed
hook up claude 3-7
1 parent d85b934 commit 7cd7d93

11 files changed

+70
-25
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ require('magenta').setup({
8484
model = "gpt-4o"
8585
},
8686
anthropic = {
87-
model = "claude-3-5-sonnet-latest"
87+
model = "claude-3-7-sonnet-latest"
8888
},
8989
bedrock = {
9090
model = "anthropic.claude-3-5-sonnet-20241022-v2:0",

lua/magenta/actions.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ end
6060

6161
M.pick_provider = function()
6262
local items = {
63+
'anthropic claude-3-7-sonnet-latest',
64+
'anthropic claude-3-5-sonnet-latest',
6365
'openai gpt-4o',
6466
'openai o1',
65-
'openai o1-mini',
66-
'anthropic claude-3-5-sonnet-latest'
67+
'openai o1-mini'
6768
}
6869
vim.ui.select(items, { prompt = "Select Model", }, function (choice)
6970
if choice ~= nil then

lua/magenta/options.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local defaults = {
66
model = "gpt-4o"
77
},
88
anthropic = {
9-
model = "claude-3-5-sonnet-latest"
9+
model = "claude-3-7-sonnet-latest"
1010
},
1111
bedrock = {
1212
model = "anthropic.claude-3-5-sonnet-20241022-v2:0",

node/chat/chat.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function init({ nvim, lsp }: { nvim: Nvim; lsp: Lsp }) {
112112
lastUserMessageId: counter.last() as Message.MessageId,
113113
providerSetting: {
114114
provider: "anthropic",
115-
model: "claude-3-5-sonnet-latest",
115+
model: "claude-3-7-sonnet-latest",
116116
},
117117
conversation: {
118118
state: "stopped",

node/magenta.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ Awaiting response ⠁`);
8383

8484
expect(state.model.providerSetting).toEqual({
8585
provider: "anthropic",
86-
model: "claude-3-5-sonnet-latest",
86+
model: "claude-3-7-sonnet-latest",
8787
});
8888
}
8989
await driver.showSidebar();
9090
const displayState = driver.getVisibleState();
9191
{
9292
const winbar = await displayState.inputWindow.getOption("winbar");
9393
expect(winbar).toBe(
94-
`Magenta Input (anthropic claude-3-5-sonnet-latest)`,
94+
`Magenta Input (anthropic claude-3-7-sonnet-latest)`,
9595
);
9696
}
9797
await driver.nvim.call("nvim_command", ["Magenta provider openai"]);

node/magenta.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class Magenta {
5757
}
5858
this.sidebar = new Sidebar(this.nvim, {
5959
provider: "anthropic",
60-
model: "claude-3-5-sonnet-latest",
60+
model: "claude-3-7-sonnet-latest",
6161
});
6262

6363
this.chatModel = Chat.init({ nvim, lsp });

node/options.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export type MagentaOptions = {
1111
export const DEFAULT_OPTIONS: MagentaOptions = {
1212
provider: "anthropic",
1313
anthropic: {
14-
model: "claude-3-5-sonnet-latest",
14+
model: "claude-3-7-sonnet-latest",
1515
},
1616
openai: {
1717
model: "gpt-4o",
1818
},
1919
bedrock: {
20-
model: "anthropic.claude-3-5-sonnet-20241022-v2:0",
20+
model: "anthropic.claude-3-7-sonnet-20241022-v2:0",
2121
promptCaching: false,
2222
},
2323
sidebarPosition: "left",

node/providers/anthropic.spec.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, it, expect } from "vitest";
22
import { placeCacheBreakpoints } from "./anthropic.ts";
33
import type { MessageParam } from "./anthropic.ts";
4+
import type {
5+
TextBlockParam,
6+
ToolUseBlockParam,
7+
} from "@anthropic-ai/sdk/resources/index.mjs";
48

59
describe("anthropic.ts", () => {
610
it("placeCacheBreakpoints should add cache markers at appropriate positions", () => {
@@ -26,11 +30,17 @@ describe("anthropic.ts", () => {
2630

2731
placeCacheBreakpoints(messages);
2832

29-
expect(messages[0].content[0].cache_control).toBeUndefined();
33+
expect(
34+
(messages[0].content[0] as TextBlockParam).cache_control,
35+
).toBeUndefined();
3036

31-
expect(messages[0].content[1].cache_control).toEqual({ type: "ephemeral" });
37+
expect((messages[0].content[1] as TextBlockParam).cache_control).toEqual({
38+
type: "ephemeral",
39+
});
3240

33-
expect(messages[0].content[2].cache_control).toEqual({ type: "ephemeral" });
41+
expect((messages[0].content[2] as TextBlockParam).cache_control).toEqual({
42+
type: "ephemeral",
43+
});
3444
});
3545

3646
it("placeCacheBreakpoints should handle mixed content types", () => {
@@ -54,8 +64,12 @@ describe("anthropic.ts", () => {
5464

5565
placeCacheBreakpoints(messages);
5666

57-
expect(messages[0].content[0].cache_control).toBeUndefined();
58-
expect(messages[0].content[1].cache_control).toEqual({ type: "ephemeral" });
67+
expect(
68+
(messages[0].content[0] as TextBlockParam).cache_control,
69+
).toBeUndefined();
70+
expect((messages[0].content[1] as ToolUseBlockParam).cache_control).toEqual(
71+
{ type: "ephemeral" },
72+
);
5973
});
6074

6175
it("placeCacheBreakpoints should not add cache markers for small content", () => {
@@ -73,6 +87,8 @@ describe("anthropic.ts", () => {
7387

7488
placeCacheBreakpoints(messages);
7589

76-
expect(messages[0].content[0].cache_control).toBeUndefined();
90+
expect(
91+
(messages[0].content[0] as TextBlockParam).cache_control,
92+
).toBeUndefined();
7793
});
7894
});

node/providers/anthropic.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AnthropicProvider implements Provider {
4545
apiKeyRequired = true,
4646
) {
4747
const apiKey = process.env.ANTHROPIC_API_KEY;
48-
this.model = "claude-3-5-sonnet-latest";
48+
this.model = "claude-3-7-sonnet-latest";
4949

5050
if (apiKeyRequired && !apiKey) {
5151
throw new Error("Anthropic API key not found in config or environment");
@@ -127,12 +127,12 @@ export class AnthropicProvider implements Provider {
127127
},
128128
);
129129

130+
this.nvim.logger?.error(`anthropic model: ${this.model}`);
130131
return {
131132
messages: anthropicMessages,
132133
model: this.model,
133134
max_tokens: 4096,
134135
system: [
135-
// @ts-expect-error setting cache_control to undefined
136136
{
137137
type: "text",
138138
text: DEFAULT_SYSTEM_PROMPT,
@@ -145,7 +145,7 @@ export class AnthropicProvider implements Provider {
145145
? cacheControlItemsPlaced < 4
146146
? { type: "ephemeral" }
147147
: null
148-
: undefined,
148+
: null,
149149
},
150150
],
151151
tool_choice: {
@@ -639,7 +639,11 @@ export function placeCacheBreakpoints(messages: MessageParam[]): number {
639639
const targetLength = power * STR_CHARS_PER_TOKEN; // power is in tokens, but we want string chars instead
640640
// find the first block where we are past the target power
641641
const blockEntry = blocks.find((b) => b.acc > targetLength);
642-
if (blockEntry) {
642+
if (
643+
blockEntry &&
644+
blockEntry.block.type !== "thinking" &&
645+
blockEntry.block.type !== "redacted_thinking"
646+
) {
643647
blockEntry.block.cache_control = { type: "ephemeral" };
644648
}
645649
}

package-lock.json

+28-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"vitest": "^2.1.8"
99
},
1010
"dependencies": {
11-
"@anthropic-ai/sdk": "^0.36.2",
1211
"@anthropic-ai/bedrock-sdk": "^0.12.4",
12+
"@anthropic-ai/sdk": "^0.37.0",
1313
"eslint": "^9.17.0",
1414
"ignore": "^7.0.0",
1515
"nvim-node": "0.0.2",

0 commit comments

Comments
 (0)