Skip to content

Commit

Permalink
refactor(types): improve tool type names (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie authored Oct 7, 2024
1 parent fd42469 commit 18dbe77
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 90 deletions.
4 changes: 4 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Types:
- <code><a href="./src/resources/messages.ts">TextBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">TextDelta</a></code>
- <code><a href="./src/resources/messages.ts">Tool</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoice</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoiceAny</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoiceAuto</a></code>
- <code><a href="./src/resources/messages.ts">ToolChoiceTool</a></code>
- <code><a href="./src/resources/messages.ts">ToolResultBlockParam</a></code>
- <code><a href="./src/resources/messages.ts">ToolUseBlock</a></code>
- <code><a href="./src/resources/messages.ts">ToolUseBlockParam</a></code>
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ export namespace Anthropic {
export import TextBlockParam = API.TextBlockParam;
export import TextDelta = API.TextDelta;
export import Tool = API.Tool;
export import ToolChoice = API.ToolChoice;
export import ToolChoiceAny = API.ToolChoiceAny;
export import ToolChoiceAuto = API.ToolChoiceAuto;
export import ToolChoiceTool = API.ToolChoiceTool;
export import ToolResultBlockParam = API.ToolResultBlockParam;
export import ToolUseBlock = API.ToolUseBlock;
export import ToolUseBlockParam = API.ToolUseBlockParam;
Expand Down
52 changes: 7 additions & 45 deletions src/resources/beta/prompt-caching/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,7 @@ export interface MessageCreateParamsBase {
* How the model should use the provided tools. The model can use a specific tool,
* any available tool, or decide by itself.
*/
tool_choice?:
| MessageCreateParams.ToolChoiceAuto
| MessageCreateParams.ToolChoiceAny
| MessageCreateParams.ToolChoiceTool;
tool_choice?: MessagesAPI.ToolChoice;

/**
* Definitions of tools that the model may use.
Expand Down Expand Up @@ -579,54 +576,19 @@ export namespace MessageCreateParams {
}

/**
* The model will automatically decide whether to use tools.
* @deprecated use `Anthropic.Messages.ToolChoiceAuto` instead
*/
export interface ToolChoiceAuto {
type: 'auto';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output at most one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}
export type ToolChoiceAuto = MessagesAPI.ToolChoiceAuto;

/**
* The model will use any available tools.
* @deprecated use `Anthropic.Messages.ToolChoiceAny` instead
*/
export interface ToolChoiceAny {
type: 'any';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output exactly one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}
export type ToolChoiceAny = MessagesAPI.ToolChoiceAny;

/**
* The model will use the specified tool with `tool_choice.name`.
* @deprecated use `Anthropic.Messages.ToolChoiceTool` instead
*/
export interface ToolChoiceTool {
/**
* The name of the tool to use.
*/
name: string;

type: 'tool';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output exactly one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}
export type ToolChoiceTool = MessagesAPI.ToolChoiceTool;

export type MessageCreateParamsNonStreaming = PromptCachingMessagesAPI.MessageCreateParamsNonStreaming;
export type MessageCreateParamsStreaming = PromptCachingMessagesAPI.MessageCreateParamsStreaming;
Expand Down
4 changes: 4 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export {
TextBlockParam,
TextDelta,
Tool,
ToolChoice,
ToolChoiceAny,
ToolChoiceAuto,
ToolChoiceTool,
ToolResultBlockParam,
ToolUseBlock,
ToolUseBlockParam,
Expand Down
112 changes: 67 additions & 45 deletions src/resources/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,62 @@ export namespace Tool {
}
}

/**
* How the model should use the provided tools. The model can use a specific tool,
* any available tool, or decide by itself.
*/
export type ToolChoice = ToolChoiceAuto | ToolChoiceAny | ToolChoiceTool;

/**
* The model will use any available tools.
*/
export interface ToolChoiceAny {
type: 'any';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output exactly one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}

/**
* The model will automatically decide whether to use tools.
*/
export interface ToolChoiceAuto {
type: 'auto';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output at most one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}

/**
* The model will use the specified tool with `tool_choice.name`.
*/
export interface ToolChoiceTool {
/**
* The name of the tool to use.
*/
name: string;

type: 'tool';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output exactly one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}

export interface ToolResultBlockParam {
tool_use_id: string;

Expand Down Expand Up @@ -568,10 +624,7 @@ export interface MessageCreateParamsBase {
* How the model should use the provided tools. The model can use a specific tool,
* any available tool, or decide by itself.
*/
tool_choice?:
| MessageCreateParams.ToolChoiceAuto
| MessageCreateParams.ToolChoiceAny
| MessageCreateParams.ToolChoiceTool;
tool_choice?: ToolChoice;

/**
* Definitions of tools that the model may use.
Expand Down Expand Up @@ -686,54 +739,19 @@ export namespace MessageCreateParams {
}

/**
* The model will automatically decide whether to use tools.
* @deprecated use `Anthropic.Messages.ToolChoiceAuto` instead
*/
export interface ToolChoiceAuto {
type: 'auto';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output at most one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}
export type ToolChoiceAuto = MessagesAPI.ToolChoiceAuto;

/**
* The model will use any available tools.
* @deprecated use `Anthropic.Messages.ToolChoiceAny` instead
*/
export interface ToolChoiceAny {
type: 'any';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output exactly one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}
export type ToolChoiceAny = MessagesAPI.ToolChoiceAny;

/**
* The model will use the specified tool with `tool_choice.name`.
* @deprecated use `Anthropic.Messages.ToolChoiceTool` instead
*/
export interface ToolChoiceTool {
/**
* The name of the tool to use.
*/
name: string;

type: 'tool';

/**
* Whether to disable parallel tool use.
*
* Defaults to `false`. If set to `true`, the model will output exactly one tool
* use.
*/
disable_parallel_tool_use?: boolean;
}
export type ToolChoiceTool = MessagesAPI.ToolChoiceTool;

export type MessageCreateParamsNonStreaming = MessagesAPI.MessageCreateParamsNonStreaming;
export type MessageCreateParamsStreaming = MessagesAPI.MessageCreateParamsStreaming;
Expand Down Expand Up @@ -788,6 +806,10 @@ export namespace Messages {
export import TextBlockParam = MessagesAPI.TextBlockParam;
export import TextDelta = MessagesAPI.TextDelta;
export import Tool = MessagesAPI.Tool;
export import ToolChoice = MessagesAPI.ToolChoice;
export import ToolChoiceAny = MessagesAPI.ToolChoiceAny;
export import ToolChoiceAuto = MessagesAPI.ToolChoiceAuto;
export import ToolChoiceTool = MessagesAPI.ToolChoiceTool;
export import ToolResultBlockParam = MessagesAPI.ToolResultBlockParam;
export import ToolUseBlock = MessagesAPI.ToolUseBlock;
export import ToolUseBlockParam = MessagesAPI.ToolUseBlockParam;
Expand Down

0 comments on commit 18dbe77

Please sign in to comment.