Class: Foobara::Ai::OpenAiApi::BaseCommand
- Includes:
- HttpApiCommand
- Defined in:
- foobara-open-ai-api-1.0.1/src/foobara/ai/open_ai_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
- #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.
8 9 10 |
# File 'foobara-open-ai-api-1.0.1/src/foobara/ai/open_ai_api/base_command.rb', line 8 def api_token @api_token end |
Instance Method Details
#api_token ⇒ Object
19 20 21 |
# File 'foobara-open-ai-api-1.0.1/src/foobara/ai/open_ai_api/base_command.rb', line 19 def api_token inputs[:api_token] || BaseCommand.api_token || api_token_from_env end |
#api_token_from_env ⇒ Object
23 24 25 |
# File 'foobara-open-ai-api-1.0.1/src/foobara/ai/open_ai_api/base_command.rb', line 23 def api_token_from_env ENV.fetch("OPENAI_API_KEY", nil) end |
#build_request_headers ⇒ Object
27 28 29 |
# File 'foobara-open-ai-api-1.0.1/src/foobara/ai/open_ai_api/base_command.rb', line 27 def build_request_headers self.request_headers = { "Content-Type" => "application/json", "Authorization" => "Bearer #{api_token}" } end |
#issue_http_request(failures = 0) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'foobara-open-ai-api-1.0.1/src/foobara/ai/open_ai_api/base_command.rb', line 31 def issue_http_request(failures = 0) super() return if failures > 6 case response.code when "429" # :nocov: sleep 2 ** failures issue_http_request(failures + 1) # :nocov: when "529" # Do these even happen with openai? or only anthropic? # :nocov: failures += 1 sleep failures issue_http_request(failures) # :nocov: end end |