diff --git a/docs.json b/docs.json index 63b44a0d..a020c837 100644 --- a/docs.json +++ b/docs.json @@ -220,7 +220,8 @@ "group": "Anthropic", "pages": [ "integrations/llms/anthropic", - "integrations/llms/anthropic/prompt-caching" + "integrations/llms/anthropic/prompt-caching", + "integrations/llms/anthropic/computer-use" ] }, "integrations/llms/gemini", diff --git a/integrations/llms/anthropic/computer-use.mdx b/integrations/llms/anthropic/computer-use.mdx new file mode 100644 index 00000000..c9b55e09 --- /dev/null +++ b/integrations/llms/anthropic/computer-use.mdx @@ -0,0 +1,258 @@ +--- +title: "Computer use tool" +--- + +Anthropic computer use is fully supported in Portkey. +For more information on the computer use tool, please refer to the [Anthropic documentation](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/computer-use-tool). + + +### Usage + + ```py Python + from portkey_ai import Portkey + + # Initialize the Portkey client + portkey = Portkey( + api_key="PORTKEY_API_KEY", # Replace with your Portkey API key + virtual_key="VIRTUAL_KEY", # Add your provider's virtual key + ) + + # Create the request + response = portkey.chat.completions.create( + model="claude-4-opus-20250514", + max_tokens=3000, + thinking={ + "type": "enabled", + "budget_tokens": 2030 + }, + stream=False, + tools=[ + { + type: "computer", + computer: { + name: "computer_20250124", # This is the version of the tool + display_width_px: 1024, + display_height_px: 768, + display_number: 1 + } + }, + { + type: "text_editor_20250429", + name: "str_replace_based_edit_tool" + }, + { + type: "bash_20250124", + name: "bash" + } + ], + messages=[ + { + role: "user", + content: "Save a picture of a cat to my desktop." + } + ] + ) + print(response) + + ``` + ```ts NodeJS + import Portkey from 'portkey-ai'; + + // Initialize the Portkey client + const portkey = new Portkey({ + apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key + virtualKey: "VIRTUAL_KEY", // Add your anthropic's virtual key + strictOpenAiCompliance: false + }); + + // Generate a chat completion + async function getChatCompletionFunctions() { + const response = await portkey.chat.completions.create({ + model: "claude-4-opus-20250514", + max_tokens: 3000, + thinking: { + type: "enabled", + budget_tokens: 2030 + }, + stream: false, + tools: [ + { + type: "computer", + computer: { + name: "computer_20250124", // This is the version of the tool + display_width_px: 1024, + display_height_px: 768, + display_number: 1 + } + }, + { + type: "text_editor_20250429", + name: "str_replace_based_edit_tool" + }, + { + type: "bash_20250124", + name: "bash" + } + ], + "messages": [ + { + role: "user", + content: "Save a picture of a cat to my desktop." + } + ] + }); + console.log(response); + } + // Call the function + getChatCompletionFunctions(); + ``` + ```js OpenAI NodeJS + import OpenAI from 'openai'; + import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai' + + const openai = new OpenAI({ + apiKey: 'ANTHROPIC_API_KEY', // defaults to process.env["OPENAI_API_KEY"], + baseURL: PORTKEY_GATEWAY_URL, + defaultHeaders: createHeaders({ + provider: "anthropic", + apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"] + strictOpenAiCompliance: false + }) + }); + + // Generate a chat completion with streaming + async function getChatCompletionFunctions(){ + const response = await openai.chat.completions.create({ + model: "claude-4-opus-20250514", + max_tokens: 3000, + thinking: { + type: "enabled", + budget_tokens: 2030 + }, + stream: false, + tools: [ + { + type: "computer", + computer: { + name: "computer_20250124", // This is the version of the tool + display_width_px: 1024, + display_height_px: 768, + display_number: 1 + } + }, + { + type: "text_editor_20250429", + name: "str_replace_based_edit_tool" + }, + { + type: "bash_20250124", + name: "bash" + } + ], + messages: [ + { + role: "user", + content: "Save a picture of a cat to my desktop." + } + ] + }); + + console.log(response) + } + await getChatCompletionFunctions(); + ``` + ```py OpenAI Python + from openai import OpenAI + from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders + + openai = OpenAI( + api_key='Anthropic_API_KEY', + base_url=PORTKEY_GATEWAY_URL, + default_headers=createHeaders( + provider="anthropic", + api_key="PORTKEY_API_KEY", + strict_open_ai_compliance=False + ) + ) + + + response = openai.chat.completions.create( + model="claude-4-opus-20250514", + max_tokens=3000, + thinking={ + "type": "enabled", + "budget_tokens": 2030 + }, + stream=False, + tools=[ + { + type: "computer", + computer: { + name: "computer_20250124", # This is the version of the tool + display_width_px: 1024, + display_height_px: 768, + display_number: 1 + } + }, + { + type: "text_editor_20250429", + name: "str_replace_based_edit_tool" + }, + { + type: "bash_20250124", + name: "bash" + } + ], + messages=[ + { + role: "user", + content: "Save a picture of a cat to my desktop." + } + ] + ) + + print(response) + ``` + ```sh cURL + curl "https://api.portkey.ai/v1/chat/completions" \ + -H "Content-Type: application/json" \ + -H "x-portkey-api-key: $PORTKEY_API_KEY" \ + -H "x-portkey-provider: anthropic" \ + -H "x-api-key: $ANTHROPIC_API_KEY" \ + -H "x-portkey-strict-open-ai-compliance: false" \ + -d '{ + "model": "claude-4-opus-20250514", + "max_tokens": 3000, + "thinking": { + "type": "enabled", + "budget_tokens": 2030 + }, + "stream": false, + "tools": [ + { + "type": "computer", + "computer": { + "name": "computer_20250124", + "display_width_px": 1024, + "display_height_px": 768, + "display_number": 1 + } + }, + { + "type": "text_editor_20250429", + "name": "str_replace_based_edit_tool" + }, + { + "type": "bash_20250124", + "name": "bash" + } + ], + "messages": [ + { + "role": "user", + "content": "Save a picture of a cat to my desktop." + } + ] + }' + ``` +