From 0ed0cc52a2dc16c732f0f8fd7e4439db920d391d Mon Sep 17 00:00:00 2001 From: Alessandro Pignotti Date: Mon, 3 Mar 2025 17:05:31 +0100 Subject: [PATCH] Claude: Support thinking mode --- postcss.config.js | 1 + src/lib/AnthropicTab.svelte | 11 ++++++++++- src/lib/anthropic.js | 12 ++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/postcss.config.js b/postcss.config.js index 44f65ec..bc2f331 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -24,6 +24,7 @@ export default { case '.fa-mouse-pointer:before': case '.fa-hourglass-half:before': case '.fa-hand:before': + case '.fa-brain:before': case '.fa-keyboard:before': case '.fa-brands:before': case '.fa-solid:before': diff --git a/src/lib/AnthropicTab.svelte b/src/lib/AnthropicTab.svelte index f3bc4b6..ebe4d35 100644 --- a/src/lib/AnthropicTab.svelte +++ b/src/lib/AnthropicTab.svelte @@ -1,5 +1,5 @@

Claude AI Integration

WebVM is integrated with Claude by Anthropic AI. You can prompt the AI to control the system.

@@ -114,6 +122,7 @@

Conversation history +

diff --git a/src/lib/anthropic.js b/src/lib/anthropic.js index 38e44ac..7939701 100644 --- a/src/lib/anthropic.js +++ b/src/lib/anthropic.js @@ -38,14 +38,17 @@ async function sendMessages(handleTool) { var dc = get(displayConfig); var tool = dc ? { type: "computer_20250124", name: "computer", display_width_px: dc.width, display_height_px: dc.height, display_number: 1 } : { type: "bash_20250124", name: "bash" } - const response = await client.beta.messages.create({max_tokens: 1024, + const config = {max_tokens: 2048, messages: messages, system: "You are running on a virtualized machine. Wait some extra time after all operations to compensate for slowdown.", model: 'claude-3-7-sonnet-20250219', tools: [tool], tool_choice: {type: "auto", disable_parallel_tool_use: true}, betas: ["computer-use-2025-01-24"] - }); + }; + if(get(enableThinking)) + config.thinking = { type: "enabled", budget_tokens: 1024 }; + const response = await client.beta.messages.create(config); if(stopFlag) { aiActivity.set(false); @@ -97,6 +100,10 @@ async function sendMessages(handleTool) } sendMessages(handleTool); } + else if(c.type == "thinking") + { + addMessageInternal(response.role, [c]); + } else { console.warn(`Invalid response type: ${c.type}`); @@ -156,6 +163,7 @@ export const apiState = writable("KEY_REQUIRED"); export const messageList = writable(messages); export const currentMessage = writable(""); export const displayConfig = writable(null); +export const enableThinking = writable(false); if(browser) initialize();