Class: Neh::Cli::O

Inherits:
Object
  • Object
show all
Defined in:
lib/neh/cli/o.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args, options:) ⇒ O

Returns a new instance of O.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/neh/cli/o.rb', line 14

def initialize(*args, options:)
  @message = args.join(' ')

  @options = options
  server_host = ENV.fetch('NEH_SERVER_HOST', 'yoryo.gipcompany.com')
  server_port = ENV.fetch('NEH_SERVER_PORT', 443)
  @channel = 'LargeLanguageModelQueryChannel'

  url = "ws://#{server_host}:#{server_port}/cable"
  @endpoint = Async::HTTP::Endpoint.parse(url)
end

Instance Method Details

#executeObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/neh/cli/o.rb', line 26

def execute
  Async do |_task|
    Async::WebSocket::Client.connect(@endpoint, headers: { 'Authorization' => "Bearer #{token}" }) do |connection|
      while (message = connection.read)
        parsed_message =
          JSON.parse(message, symbolize_names: true)

        on_receive(connection, parsed_message)
      end
    end
  end
end