Class: AskChatgpt::Executor

Inherits:
Object
  • Object
show all
Includes:
DefaultBehavior, Sugar
Defined in:
lib/ask_chatgpt/executor.rb

Constant Summary

Constants included from DefaultBehavior

DefaultBehavior::DEFAULT_PROMPTS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sugar

#async!, #debug!, #off!, #on!, #sync!

Methods included from DefaultBehavior

#add_prompt, #with_model

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

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/ask_chatgpt/executor.rb', line 20

def client
  @client
end

#cursorObject (readonly)

Returns the value of attribute cursor.



20
21
22
# File 'lib/ask_chatgpt/executor.rb', line 20

def cursor
  @cursor
end

#scopeObject (readonly)

Returns the value of attribute scope.



20
21
22
# File 'lib/ask_chatgpt/executor.rb', line 20

def scope
  @scope
end

#spinnerObject (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

.callObject



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

#inspectObject



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.message
rescue StandardError => e
  puts e.message
  puts e.backtrace.take(5).join("\n")
rescue Exception => e
  puts e.message
ensure
  nil
end

#speakObject 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