-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanity_check.rb
59 lines (51 loc) · 1.34 KB
/
sanity_check.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
require 'anthropic'
Anthropic.setup do |config|
config.api_key = ENV.fetch('ANTHROPIC_API_KEY')
end
puts "\nTesting non-streaming messages API"
puts Anthropic.messages.create(
model: 'claude-2.1',
max_tokens: 200,
messages: [{ role: 'user', content: 'Yo what up?' }]
)
puts "\nTesting streaming messages API"
Anthropic.messages.create(
model: 'claude-2.1',
max_tokens: 200,
messages: [{ role: 'user', content: 'Yo what up?' }],
stream: true
) { |event| puts event }
puts "\nTesting tools"
tools = [
{
name: 'get_weather',
description: 'Get the current weather in a given location',
input_schema: {
type: 'object',
properties: {
location: { type: 'string' }
},
required: ['location']
}
}
]
puts Anthropic.messages(beta: 'tools-2024-04-04').create(
model: 'claude-3-opus-20240229',
max_tokens: 200,
tools:,
messages: [{ role: 'user', content: 'What is the weather like in Nashville?' }]
)
puts "\nTesting completions API"
puts Anthropic.completions.create(
model: 'claude-2',
max_tokens_to_sample: 200,
prompt: 'Human: Yo what up?\n\nAssistant:'
)
puts "\nTesting streaming completions API"
Anthropic.completions.create(
model: 'claude-2',
max_tokens_to_sample: 200,
prompt: 'Human: Yo what up?\n\nAssistant:',
stream: true
) { |event| puts event }