From b9fa45a04db46fcf3a1b046f589ae55a081e15df Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Tue, 22 Oct 2024 15:20:07 +0100 Subject: [PATCH] feat(api): add new model and `computer-use-2024-10-22` beta https://www.anthropic.com/news/3-5-models-and-computer-use --- .stats.yml | 2 +- api.md | 4 ++ src/resources/beta/beta.ts | 10 +++- src/resources/beta/index.ts | 4 ++ src/resources/beta/messages/batches.ts | 42 ++++++++++------ src/resources/beta/messages/index.ts | 4 ++ src/resources/beta/messages/messages.ts | 49 +++++++++++++++++-- src/resources/beta/prompt-caching/messages.ts | 5 +- src/resources/messages.ts | 8 ++- .../beta/messages/batches.test.ts | 9 ++++ .../beta/messages/messages.test.ts | 3 ++ 11 files changed, 117 insertions(+), 23 deletions(-) diff --git a/.stats.yml b/.stats.yml index 6908c7eb..46f41749 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 9 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-b1f4e59681c4caad9ee2926c2e889d673290a831947c91f231ff7a1d5630d208.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-bcf4ba8fcea38089a259c148cdedd0154fa6b4a280c022abf4a038192835cefd.yml diff --git a/api.md b/api.md index ce30c20a..7b3b69cf 100644 --- a/api.md +++ b/api.md @@ -83,11 +83,15 @@ Types: - BetaTextBlockParam - BetaTextDelta - BetaTool +- BetaToolBash20241022 - BetaToolChoice - BetaToolChoiceAny - BetaToolChoiceAuto - BetaToolChoiceTool +- BetaToolComputerUse20241022 - BetaToolResultBlockParam +- BetaToolTextEditor20241022 +- BetaToolUnion - BetaToolUseBlock - BetaToolUseBlockParam - BetaUsage diff --git a/src/resources/beta/beta.ts b/src/resources/beta/beta.ts index 59a92501..7979da01 100644 --- a/src/resources/beta/beta.ts +++ b/src/resources/beta/beta.ts @@ -10,7 +10,11 @@ export class Beta extends APIResource { promptCaching: PromptCachingAPI.PromptCaching = new PromptCachingAPI.PromptCaching(this._client); } -export type AnthropicBeta = (string & {}) | 'message-batches-2024-09-24' | 'prompt-caching-2024-07-31'; +export type AnthropicBeta = + | (string & {}) + | 'message-batches-2024-09-24' + | 'prompt-caching-2024-07-31' + | 'computer-use-2024-10-22'; export interface BetaAPIError { message: string; @@ -101,11 +105,15 @@ export namespace Beta { export import BetaTextBlockParam = MessagesAPI.BetaTextBlockParam; export import BetaTextDelta = MessagesAPI.BetaTextDelta; export import BetaTool = MessagesAPI.BetaTool; + export import BetaToolBash20241022 = MessagesAPI.BetaToolBash20241022; export import BetaToolChoice = MessagesAPI.BetaToolChoice; export import BetaToolChoiceAny = MessagesAPI.BetaToolChoiceAny; export import BetaToolChoiceAuto = MessagesAPI.BetaToolChoiceAuto; export import BetaToolChoiceTool = MessagesAPI.BetaToolChoiceTool; + export import BetaToolComputerUse20241022 = MessagesAPI.BetaToolComputerUse20241022; export import BetaToolResultBlockParam = MessagesAPI.BetaToolResultBlockParam; + export import BetaToolTextEditor20241022 = MessagesAPI.BetaToolTextEditor20241022; + export import BetaToolUnion = MessagesAPI.BetaToolUnion; export import BetaToolUseBlock = MessagesAPI.BetaToolUseBlock; export import BetaToolUseBlockParam = MessagesAPI.BetaToolUseBlockParam; export import BetaUsage = MessagesAPI.BetaUsage; diff --git a/src/resources/beta/index.ts b/src/resources/beta/index.ts index 112d9ad1..3fb9b9e3 100644 --- a/src/resources/beta/index.ts +++ b/src/resources/beta/index.ts @@ -34,11 +34,15 @@ export { BetaTextBlockParam, BetaTextDelta, BetaTool, + BetaToolBash20241022, BetaToolChoice, BetaToolChoiceAny, BetaToolChoiceAuto, BetaToolChoiceTool, + BetaToolComputerUse20241022, BetaToolResultBlockParam, + BetaToolTextEditor20241022, + BetaToolUnion, BetaToolUseBlock, BetaToolUseBlockParam, BetaUsage, diff --git a/src/resources/beta/messages/batches.ts b/src/resources/beta/messages/batches.ts index 40d3de7f..84c1fc60 100644 --- a/src/resources/beta/messages/batches.ts +++ b/src/resources/beta/messages/batches.ts @@ -12,10 +12,11 @@ import { AnthropicError } from '../../../error'; export class Batches extends APIResource { /** - * Send a batch of requests to create Messages. + * Send a batch of Message creation requests. * - * The Messages Batch API can be used to process multiple Messages API requests at - * once. Once a Message Batch is created, it begins processing immediately. + * The Message Batches API can be used to process multiple Messages API requests at + * once. Once a Message Batch is created, it begins processing immediately. Batches + * can take up to 24 hours to complete. */ create(params: BatchCreateParams, options?: Core.RequestOptions): Core.APIPromise { const { betas, ...body } = params; @@ -31,8 +32,8 @@ export class Batches extends APIResource { /** * This endpoint is idempotent and can be used to poll for Message Batch - * completion. To access the results of a Message Batch, use the `responses_url` - * field in the response. + * completion. To access the results of a Message Batch, make a request to the + * `results_url` field in the response. */ retrieve( messageBatchId: string, @@ -59,7 +60,8 @@ export class Batches extends APIResource { } /** - * List all Message Batches within a Workspace. + * List all Message Batches within a Workspace. Most recently created batches are + * returned first. */ list( params?: BatchListParams, @@ -85,8 +87,15 @@ export class Batches extends APIResource { } /** - * Batches may be canceled any time before processing ends. The system may complete - * any in-progress, non-interruptible operations before finalizing cancellation. + * Batches may be canceled any time before processing ends. Once cancellation is + * initiated, the batch enters a `canceling` state, at which time the system may + * complete any in-progress, non-interruptible requests before finalizing + * cancellation. + * + * The number of canceled requests is specified in `request_counts`. To determine + * which requests were canceled, check the individual results within the batch. + * Note that cancellation may not result in any canceled requests if they were + * non-interruptible. */ cancel( messageBatchId: string, @@ -168,6 +177,12 @@ export interface BetaMessageBatch { */ id: string; + /** + * RFC 3339 datetime string representing the time at which the Message Batch was + * archived and its results became unavailable. + */ + archived_at: string | null; + /** * RFC 3339 datetime string representing the time at which cancellation was * initiated for the Message Batch. Specified only if cancellation was initiated. @@ -197,16 +212,15 @@ export interface BetaMessageBatch { /** * Processing status of the Message Batch. - * - * This is one of: `in_progress`, `canceling`, or `ended`. */ processing_status: 'in_progress' | 'canceling' | 'ended'; /** - * Overview of the number of requests within the Message Batch and their statuses. + * Tallies requests within the Message Batch, categorized by their status. * * Requests start as `processing` and move to one of the other statuses only once - * processing of entire batch ends. + * processing of the entire batch ends. The sum of all values always matches the + * total number of requests in the batch. */ request_counts: BetaMessageBatchRequestCounts; @@ -244,7 +258,7 @@ export interface BetaMessageBatchExpiredResult { export interface BetaMessageBatchIndividualResponse { /** * Developer-provided ID created for each request in a Message Batch. Useful for - * matching results to requests. + * matching results to requests, as results may be given out of request order. * * Must be unique for each request within the Message Batch. */ @@ -331,7 +345,7 @@ export namespace BatchCreateParams { export interface Request { /** * Developer-provided ID created for each request in a Message Batch. Useful for - * matching results to requests. + * matching results to requests, as results may be given out of request order. * * Must be unique for each request within the Message Batch. */ diff --git a/src/resources/beta/messages/index.ts b/src/resources/beta/messages/index.ts index 54759740..9011e21b 100644 --- a/src/resources/beta/messages/index.ts +++ b/src/resources/beta/messages/index.ts @@ -21,11 +21,15 @@ export { BetaTextBlockParam, BetaTextDelta, BetaTool, + BetaToolBash20241022, BetaToolChoice, BetaToolChoiceAny, BetaToolChoiceAuto, BetaToolChoiceTool, + BetaToolComputerUse20241022, BetaToolResultBlockParam, + BetaToolTextEditor20241022, + BetaToolUnion, BetaToolUseBlock, BetaToolUseBlockParam, BetaUsage, diff --git a/src/resources/beta/messages/messages.ts b/src/resources/beta/messages/messages.ts index d8d0d003..cb1f1659 100644 --- a/src/resources/beta/messages/messages.ts +++ b/src/resources/beta/messages/messages.ts @@ -323,6 +323,8 @@ export interface BetaTool { * aspects of the tool input JSON schema. */ description?: string; + + type?: 'custom' | null; } export namespace BetaTool { @@ -340,6 +342,14 @@ export namespace BetaTool { } } +export interface BetaToolBash20241022 { + name: 'bash'; + + type: 'bash_20241022'; + + cache_control?: BetaCacheControlEphemeral | null; +} + /** * How the model should use the provided tools. The model can use a specific tool, * any available tool, or decide by itself. @@ -396,6 +406,20 @@ export interface BetaToolChoiceTool { disable_parallel_tool_use?: boolean; } +export interface BetaToolComputerUse20241022 { + display_height_px: number; + + display_width_px: number; + + name: 'computer'; + + type: 'computer_20241022'; + + cache_control?: BetaCacheControlEphemeral | null; + + display_number?: number | null; +} + export interface BetaToolResultBlockParam { tool_use_id: string; @@ -408,6 +432,20 @@ export interface BetaToolResultBlockParam { is_error?: boolean; } +export interface BetaToolTextEditor20241022 { + name: 'str_replace_editor'; + + type: 'text_editor_20241022'; + + cache_control?: BetaCacheControlEphemeral | null; +} + +export type BetaToolUnion = + | BetaTool + | BetaToolComputerUse20241022 + | BetaToolBash20241022 + | BetaToolTextEditor20241022; + export interface BetaToolUseBlock { id: string; @@ -472,11 +510,12 @@ export interface MessageCreateParamsBase { * Our models are trained to operate on alternating `user` and `assistant` * conversational turns. When creating a new `Message`, you specify the prior * conversational turns with the `messages` parameter, and the model then generates - * the next `Message` in the conversation. + * the next `Message` in the conversation. Consecutive `user` or `assistant` turns + * in your request will be combined into a single turn. * * Each input message must be an object with a `role` and `content`. You can * specify a single `user`-role message, or you can include multiple `user` and - * `assistant` messages. The first message must always use the `user` role. + * `assistant` messages. * * If the final message uses the `assistant` role, the response content will * continue immediately from the content in that message. This can be used to @@ -686,7 +725,7 @@ export interface MessageCreateParamsBase { * * See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details. */ - tools?: Array; + tools?: Array; /** * Body param: Only sample from the top K options for each subsequent token. @@ -766,11 +805,15 @@ export namespace Messages { export import BetaTextBlockParam = MessagesMessagesAPI.BetaTextBlockParam; export import BetaTextDelta = MessagesMessagesAPI.BetaTextDelta; export import BetaTool = MessagesMessagesAPI.BetaTool; + export import BetaToolBash20241022 = MessagesMessagesAPI.BetaToolBash20241022; export import BetaToolChoice = MessagesMessagesAPI.BetaToolChoice; export import BetaToolChoiceAny = MessagesMessagesAPI.BetaToolChoiceAny; export import BetaToolChoiceAuto = MessagesMessagesAPI.BetaToolChoiceAuto; export import BetaToolChoiceTool = MessagesMessagesAPI.BetaToolChoiceTool; + export import BetaToolComputerUse20241022 = MessagesMessagesAPI.BetaToolComputerUse20241022; export import BetaToolResultBlockParam = MessagesMessagesAPI.BetaToolResultBlockParam; + export import BetaToolTextEditor20241022 = MessagesMessagesAPI.BetaToolTextEditor20241022; + export import BetaToolUnion = MessagesMessagesAPI.BetaToolUnion; export import BetaToolUseBlock = MessagesMessagesAPI.BetaToolUseBlock; export import BetaToolUseBlockParam = MessagesMessagesAPI.BetaToolUseBlockParam; export import BetaUsage = MessagesMessagesAPI.BetaUsage; diff --git a/src/resources/beta/prompt-caching/messages.ts b/src/resources/beta/prompt-caching/messages.ts index a1b4c110..f946a8f9 100644 --- a/src/resources/beta/prompt-caching/messages.ts +++ b/src/resources/beta/prompt-caching/messages.ts @@ -323,11 +323,12 @@ export interface MessageCreateParamsBase { * Our models are trained to operate on alternating `user` and `assistant` * conversational turns. When creating a new `Message`, you specify the prior * conversational turns with the `messages` parameter, and the model then generates - * the next `Message` in the conversation. + * the next `Message` in the conversation. Consecutive `user` or `assistant` turns + * in your request will be combined into a single turn. * * Each input message must be an object with a `role` and `content`. You can * specify a single `user`-role message, or you can include multiple `user` and - * `assistant` messages. The first message must always use the `user` role. + * `assistant` messages. * * If the final message uses the `assistant` role, the response content will * continue immediately from the content in that message. This can be used to diff --git a/src/resources/messages.ts b/src/resources/messages.ts index 542f7c01..b687d393 100644 --- a/src/resources/messages.ts +++ b/src/resources/messages.ts @@ -229,7 +229,10 @@ export interface Metadata { */ export type Model = | (string & {}) + | 'claude-3-5-sonnet-latest' + | 'claude-3-5-sonnet-20241022' | 'claude-3-5-sonnet-20240620' + | 'claude-3-opus-latest' | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' @@ -492,11 +495,12 @@ export interface MessageCreateParamsBase { * Our models are trained to operate on alternating `user` and `assistant` * conversational turns. When creating a new `Message`, you specify the prior * conversational turns with the `messages` parameter, and the model then generates - * the next `Message` in the conversation. + * the next `Message` in the conversation. Consecutive `user` or `assistant` turns + * in your request will be combined into a single turn. * * Each input message must be an object with a `role` and `content`. You can * specify a single `user`-role message, or you can include multiple `user` and - * `assistant` messages. The first message must always use the `user` role. + * `assistant` messages. * * If the final message uses the `assistant` role, the response content will * continue immediately from the content in that message. This can be used to diff --git a/tests/api-resources/beta/messages/batches.test.ts b/tests/api-resources/beta/messages/batches.test.ts index 4bc02208..6437483c 100644 --- a/tests/api-resources/beta/messages/batches.test.ts +++ b/tests/api-resources/beta/messages/batches.test.ts @@ -79,6 +79,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -94,6 +95,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -109,6 +111,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, ], top_k: 5, @@ -144,6 +147,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -159,6 +163,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -174,6 +179,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, ], top_k: 5, @@ -209,6 +215,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -224,6 +231,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -239,6 +247,7 @@ describe('resource batches', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, ], top_k: 5, diff --git a/tests/api-resources/beta/messages/messages.test.ts b/tests/api-resources/beta/messages/messages.test.ts index 2a5f6433..b9c98f61 100644 --- a/tests/api-resources/beta/messages/messages.test.ts +++ b/tests/api-resources/beta/messages/messages.test.ts @@ -47,6 +47,7 @@ describe('resource messages', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -59,6 +60,7 @@ describe('resource messages', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, { input_schema: { @@ -71,6 +73,7 @@ describe('resource messages', () => { name: 'x', cache_control: { type: 'ephemeral' }, description: 'Get the current weather in a given location', + type: 'custom', }, ], top_k: 5,