Class: Foobara::Ai::AnthropicApi::BaseCommand
- Includes:
- HttpApiCommand
- Defined in:
- foobara-anthropic-api-1.0.3/src/foobara/ai/anthropic_api/base_command.rb
Direct Known Subclasses
Constant Summary
Constants included from TruncatedInspect
Class Attribute Summary collapse
-
.api_token ⇒ Object
Returns the value of attribute api_token.
Attributes included from CommandPatternImplementation::Concerns::Subcommands
Attributes included from CommandPatternImplementation::Concerns::Runtime
#exception, #outcome, #raw_result
Attributes included from CommandPatternImplementation::Concerns::Errors
Attributes included from CommandPatternImplementation::Concerns::Inputs
Instance Method Summary collapse
- #anthropic_version ⇒ Object
- #api_token ⇒ Object
- #api_token_from_env ⇒ Object
- #build_request_headers ⇒ Object
- #issue_http_request(failures = 0) ⇒ Object
Methods inherited from Command
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods included from CommandPatternImplementation::Concerns::Reflection
Methods included from CommandPatternImplementation::Concerns::DomainMappers
#domain_map, #domain_map!, #run_mapped_subcommand!
Methods included from CommandPatternImplementation::Concerns::Subcommands
#run_subcommand!, #subcommand?
Methods included from CommandPatternImplementation::Concerns::Entities
Methods included from CommandPatternImplementation::Concerns::Transactions
Methods included from NestedTransactionable
#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, #relevant_entity_classes, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction, with_needed_transactions_for_type
Methods included from CommandPatternImplementation::Concerns::StateMachine
Methods included from CommandPatternImplementation::Concerns::Callbacks
#state_machine_callback_registry
Methods included from CommandPatternImplementation::Concerns::Runtime
#execute, #halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records
Methods included from CommandPatternImplementation::Concerns::Errors
Methods included from CommandPatternImplementation::Concerns::Inputs
#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?
Methods included from CommandPatternImplementation::Concerns::ResultType
Methods included from CommandPatternImplementation::Concerns::InputsType
Methods included from TruncatedInspect
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs
Class Attribute Details
.api_token ⇒ Object
Returns the value of attribute api_token.
10 11 12 |
# File 'foobara-anthropic-api-1.0.3/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 'foobara-anthropic-api-1.0.3/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 'foobara-anthropic-api-1.0.3/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 'foobara-anthropic-api-1.0.3/src/foobara/ai/anthropic_api/base_command.rb', line 34 def api_token_from_env ENV.fetch("ANTHROPIC_API_KEY", nil) end |
#build_request_headers ⇒ Object
22 23 24 25 26 27 28 |
# File 'foobara-anthropic-api-1.0.3/src/foobara/ai/anthropic_api/base_command.rb', line 22 def build_request_headers self.request_headers = { "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 'foobara-anthropic-api-1.0.3/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" # TODO: figure out how to test this code path # :nocov: sleep 2 ** failures issue_http_request(failures + 1) # :nocov: when "529" # :nocov: failures += 1 sleep failures issue_http_request(failures) # :nocov: end end |