Class: Foobara::Ai::AnthropicApi::BaseCommand
- Inherits:
-
Command
- Object
- Command
- Foobara::Ai::AnthropicApi::BaseCommand
show all
- Includes:
- HttpApiCommand
- Defined in:
- foobara-anthropic-api-1.0.5/src/foobara/ai/anthropic_api/base_command.rb
Constant Summary
TruncatedInspect::MAX_LENGTH
Class Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Command
install!
#inspect, truncating
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Class Attribute Details
.api_token ⇒ Object
Returns the value of attribute api_token.
10
11
12
|
# File 'src/foobara/ai/anthropic_api/base_command.rb', line 10
def api_token
@api_token
end
|
Instance Method Details
#anthropic_version ⇒ Object
38
39
40
|
# File 'src/foobara/ai/anthropic_api/base_command.rb', line 38
def anthropic_version
inputs[:anthropic_version] || ENV.fetch("ANTHROPIC_VERSION", "2023-06-01")
end
|
#api_token ⇒ Object
30
31
32
|
# File 'src/foobara/ai/anthropic_api/base_command.rb', line 30
def api_token
inputs[:api_token] || BaseCommand.api_token || api_token_from_env
end
|
#api_token_from_env ⇒ Object
34
35
36
|
# File 'src/foobara/ai/anthropic_api/base_command.rb', line 34
def api_token_from_env
ENV.fetch("ANTHROPIC_API_KEY", nil)
end
|
22
23
24
25
26
27
28
|
# File 'src/foobara/ai/anthropic_api/base_command.rb', line 22
def
self. = {
"Content-Type" => "application/json",
"X-Api-Key" => api_token,
"Anthropic-Version" => anthropic_version
}
end
|
#issue_http_request(failures = 0) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'src/foobara/ai/anthropic_api/base_command.rb', line 42
def issue_http_request(failures = 0)
super()
return if failures > 6
case response.code
when "429"
sleep 2 ** failures
issue_http_request(failures + 1)
when "529"
failures += 1
sleep failures
issue_http_request(failures)
end
end
|