Class: AskChatgpt::Executor
- Inherits:
-
Object
- Object
- AskChatgpt::Executor
- Includes:
- DefaultBehavior, Sugar
- Defined in:
- lib/ask_chatgpt/executor.rb
Constant Summary
Constants included from DefaultBehavior
DefaultBehavior::DEFAULT_PROMPTS
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#spinner ⇒ Object
readonly
Returns the value of attribute spinner.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client) ⇒ Executor
constructor
A new instance of Executor.
- #inspect ⇒ Object
- #speak ⇒ Object (also: #s)
Methods included from Sugar
#async!, #debug!, #off!, #on!, #sync!
Methods included from DefaultBehavior
Constructor Details
#initialize(client) ⇒ Executor
Returns a new instance of Executor.
35 36 37 38 39 40 |
# File 'lib/ask_chatgpt/executor.rb', line 35 def initialize(client) @scope = AskChatGPT.included_prompts.dup @client = client @spinner = TTY::Spinner.new(format: :classic) @cursor = TTY::Cursor end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
20 21 22 |
# File 'lib/ask_chatgpt/executor.rb', line 20 def client @client end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
20 21 22 |
# File 'lib/ask_chatgpt/executor.rb', line 20 def cursor @cursor end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
20 21 22 |
# File 'lib/ask_chatgpt/executor.rb', line 20 def scope @scope end |
#spinner ⇒ Object (readonly)
Returns the value of attribute spinner.
20 21 22 |
# File 'lib/ask_chatgpt/executor.rb', line 20 def spinner @spinner end |
Class Method Details
.call ⇒ Object
22 23 24 25 |
# File 'lib/ask_chatgpt/executor.rb', line 22 def self.call client = OpenAI::Client.new(access_token: AskChatGPT.access_token) AskChatgpt::Executor.new(client) end |
Instance Method Details
#inspect ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ask_chatgpt/executor.rb', line 42 def inspect return if @executed @executed = true pp(executor_parameters) if AskChatGPT.debug call_with_validations do case AskChatGPT.mode when :async call_async else call_sync end end nil rescue SystemExit, SignalException, InputError, NoMethodError => e puts e. rescue StandardError => e puts e. puts e.backtrace.take(5).join("\n") rescue Exception => e puts e. ensure nil end |
#speak ⇒ Object Also known as: s
27 28 29 30 31 32 |
# File 'lib/ask_chatgpt/executor.rb', line 27 def speak puts "Voice input is not enabled (docs: https://github.com/railsjazz/ask_chatgpt)" unless AskChatGPT.voice_enabled puts "Audio device ID is not configured (docs: https://github.com/railsjazz/ask_chatgpt)" unless AskChatGPT.audio_device_id AskChatgpt::VoiceFlow::Voice.new.run end |