Skip to content

Commit

Permalink
Move tools use out of beta (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
dickdavis authored Jun 26, 2024
1 parent 16710a7 commit 8dc87ec
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 31 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end
# Hello! Not much up with me, I'm an AI assistant created by Anthropic.
```

You can also experiment with the new tools beta by passing the `beta` name when calling the API. This will ensure each request includes the correct beta header and validate properly.
You can also pass in a list of tools the assistant can use. You can find out more information about tools in the [documentation](https://docs.anthropic.com/claude/docs/tool-use).

```ruby
tools = [
Expand All @@ -107,16 +107,14 @@ tools = [
}
]

Anthropic.messages(beta: 'tools-2024-04-04').create(
Anthropic.messages.create(
model: 'claude-3-opus-20240229',
max_tokens: 200,
tools:,
messages: [{role: 'user', content: 'What is the weather like in Nashville?'}]
)
```

Streaming is currently not supported by the tools beta. You can find out more information about tools in the [documentation](https://docs.anthropic.com/claude/docs/tool-use).

### Completions API

To make a request to the Completions API:
Expand Down
3 changes: 0 additions & 3 deletions lib/anthropic/api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class SchemaValidationError < StandardError; end
# Error for when the API version is not supported.
class UnsupportedApiVersionError < StandardError; end

# Error for when a beta feature is not used correctly.
class UnsupportedBetaUseError < StandardError; end

# Error for when the provided beta is not supported.
class UnsupportedBetaError < StandardError; end

Expand Down
7 changes: 1 addition & 6 deletions lib/anthropic/api/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ module Api
# Provides bindings for the Anthropic messages API
class Messages < Base
def create(**params, &)
streaming = params[:stream]
if streaming && beta_loaded?('tools-2024-04-04')
raise Anthropic::Api::UnsupportedBetaUseError, 'Tool use is not yet supported in streaming mode'
end

validate!(params)
return post(params) unless streaming
return post(params) unless params[:stream]

post_as_stream(params, &)
end
Expand Down
2 changes: 1 addition & 1 deletion sanity_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
stream: true
) { |event| puts event }

puts "\nTesting tools beta"
puts "\nTesting tools"
tools = [
{
name: 'get_weather',
Expand Down
4 changes: 2 additions & 2 deletions schemas/betas/tools-2024-04-04.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "tools-2024-04-04",
"name": "Tools",
"description": "Equips Claude with custom tools for interacting with clients for a wide variety of tasks.",
"name": "[Deprecated] Tools",
"description": "[Deprecated] Equips Claude with custom tools for interacting with clients for a wide variety of tasks.",
"documentation": "https://docs.anthropic.com/claude/docs/tool-use",
"header" : { "anthropic-beta": "tools-2024-04-04" },
"schema": {
Expand Down
17 changes: 17 additions & 0 deletions schemas/versions/messages/2023-06-01.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
"temperature": {
"type": "number"
},
"tools": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"input_schema": {
"type": "object"
}
}
}
},
"top_k": {
"type": "integer"
},
Expand Down
15 changes: 0 additions & 15 deletions spec/lib/anthropic/api/messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@
.to have_requested(:post, 'https://api.anthropic.com/v1/messages')
.with(headers: { 'anthropic-beta' => 'tools-2024-04-04' })
end

context 'when the request is for streaming' do # rubocop:disable RSpec/NestedGroups
let(:params) do
{
model: 'claude-2.1',
messages: [{ role: 'user', content: 'foo' }],
max_tokens: 200,
stream: true
}
end

it 'raises an error' do
expect { call_method }.to raise_error(Anthropic::Api::UnsupportedBetaUseError)
end
end
end

context 'with valid params' do
Expand Down

0 comments on commit 8dc87ec

Please sign in to comment.