neh 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c27c44b5820241a8c0458fbf980dc4e815d1b68d144b1c5f34499e7ac7f82938
4
- data.tar.gz: 91bff8dfbee7464c4d88ca05ace0abb862c2224d977fe1dde66800898fa69406
3
+ metadata.gz: 9ee23f077b2167f86dc40dcf5d0f2c1d8d04f806ebf883cb4b926778a549d37c
4
+ data.tar.gz: 95cf5614fa37ae4abcbddcfdca91bd364580c2aaf4fe73c99d0fdac13799009e
5
5
  SHA512:
6
- metadata.gz: dadbf680339bbd0bcb496c4e6b258cbafe64e6729d9742447f4334196dc35d15201cf7dbbf5c8820f7ea7eb08b3aacb36420a855e1e68eab459364f364f0be38
7
- data.tar.gz: 48ade2299fad19e7b6bd6b5218de2ce0e26499b281d8acfb43e3334f5211388a48ee9d848738d2488ca966d289fe6ae07ac9d706fd2d6bc943d7b67713e67e96
6
+ metadata.gz: f0348653539a6f078c28a17544b5a0ca9119458457774937b1e6cbcf5ec59a8038a36992f03885f0fca7773ad1e975a7241c25471ead5055495ff453cebeeb1e
7
+ data.tar.gz: f4c05d264f7ec7669d846e83eea18680e0178b0830f5ecfdce5cf0a1898c5cb1190e4bcb3f65b7692a7da18d4df2553977359d4a38d55ccf64cca16599bbe05a
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ require 'net/http'
5
+ require 'async'
6
+ require 'async/io/stream'
7
+ require 'async/http/endpoint'
8
+ require 'async/websocket/client'
9
+ require 'ruby-progressbar'
10
+ require 'faraday'
11
+ require 'pry'
12
+
13
+ class Neh::Cli::Base
14
+ def initialize(*args, options:)
15
+ @message = args.join(' ')
16
+
17
+ @options = options
18
+ server_host = ENV.fetch('NEH_SERVER_HOST', 'yoryo.gipcompany.com')
19
+ server_port = ENV.fetch('NEH_SERVER_PORT', 443)
20
+ @channel = 'LargeLanguageModelQueryChannel'
21
+
22
+ url = "ws://#{server_host}:#{server_port}/cable"
23
+ @endpoint = Async::HTTP::Endpoint.parse(url)
24
+ end
25
+
26
+ def execute
27
+ Async do |_task|
28
+ Async::WebSocket::Client.connect(@endpoint, headers: { 'Authorization' => "Bearer #{token}" }) do |connection|
29
+ while (message = connection.read)
30
+ parsed_message =
31
+ JSON.parse(message, symbolize_names: true)
32
+
33
+ on_receive(connection, parsed_message)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def token
42
+ ENV.fetch('NEH_PERSONAL_ACCESS_TOKEN')
43
+ end
44
+
45
+ def on_receive(connection, message)
46
+ if message[:type]
47
+ handle_connection_message(connection, message)
48
+ else
49
+ handle_channel_message(connection, message[:message])
50
+ end
51
+ end
52
+
53
+ def handle_connection_message(connection, message)
54
+ type = message[:type]
55
+
56
+ case type
57
+ when 'welcome'
58
+ subscribe(connection)
59
+ when 'confirm_subscription'
60
+ on_subscribed
61
+ end
62
+ end
63
+
64
+ def handle_channel_message(connection, message)
65
+ type = message[:type]
66
+
67
+ case type
68
+ when 'output'
69
+ print message[:message]
70
+ when 'worker_done'
71
+ puts ''
72
+ connection.close
73
+ end
74
+ end
75
+
76
+ def subscribe(connection)
77
+ content =
78
+ {
79
+ command: :subscribe,
80
+ identifier: {
81
+ channel: @channel
82
+ }.to_json
83
+ }
84
+ connection.write(content.to_json)
85
+ connection.flush
86
+ end
87
+
88
+ def on_subscribed
89
+ response = http_connection.post("/api/neh/#{command}") do |req|
90
+ req.body = {
91
+ message: @message,
92
+ token:
93
+ }.to_json
94
+
95
+ req.headers['Content-Type'] = 'application/json'
96
+ end
97
+
98
+ body = JSON.parse response.body
99
+ puts body['message'] if debug_mode?
100
+ end
101
+
102
+ def command
103
+ raise NotImplementedError if instance_of?(Neh::Cli::Base)
104
+
105
+ unless self.class.ancestors.include?(Neh::Cli::Base)
106
+ raise NotImplementedError, 'command method must be implemented in subclasses'
107
+ end
108
+
109
+ self.class.name.split('::').last.downcase
110
+ end
111
+
112
+ def http_connection
113
+ Faraday.new(url: "#{protocol}://#{@endpoint.hostname}:#{@endpoint.port}") do |faraday|
114
+ faraday.adapter Faraday.default_adapter
115
+ faraday.headers['Authorization'] = "Bearer #{token}"
116
+ end
117
+ end
118
+
119
+ def protocol
120
+ @endpoint.secure? ? 'https' : 'http'
121
+ end
122
+
123
+ def debug_mode?
124
+ ENV['NEH_DEBUG'] == 'true'
125
+ end
126
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Neh::Cli
4
+ class Decache < Base
5
+ end
6
+ end
data/lib/neh/cli/o.rb CHANGED
@@ -1,116 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'securerandom'
4
- require 'net/http'
5
- require 'async'
6
- require 'async/io/stream'
7
- require 'async/http/endpoint'
8
- require 'async/websocket/client'
9
- require 'ruby-progressbar'
10
- require 'faraday'
11
- require 'pry'
12
-
13
- class Neh::Cli::O
14
- def initialize(*args, options:)
15
- @message = args.join(' ')
16
-
17
- @options = options
18
- server_host = ENV.fetch('NEH_SERVER_HOST', 'yoryo.gipcompany.com')
19
- server_port = ENV.fetch('NEH_SERVER_PORT', 443)
20
- @channel = 'LargeLanguageModelQueryChannel'
21
-
22
- url = "ws://#{server_host}:#{server_port}/cable"
23
- @endpoint = Async::HTTP::Endpoint.parse(url)
24
- end
25
-
26
- def execute
27
- Async do |_task|
28
- Async::WebSocket::Client.connect(@endpoint, headers: { 'Authorization' => "Bearer #{token}" }) do |connection|
29
- while (message = connection.read)
30
- parsed_message =
31
- JSON.parse(message, symbolize_names: true)
32
-
33
- on_receive(connection, parsed_message)
34
- end
35
- end
36
- end
37
- end
38
-
39
- private
40
-
41
- def token
42
- ENV.fetch('NEH_PERSONAL_ACCESS_TOKEN')
43
- end
44
-
45
- def on_receive(connection, message)
46
- if message[:type]
47
- handle_connection_message(connection, message)
48
- else
49
- handle_channel_message(connection, message[:message])
50
- end
51
- end
52
-
53
- def handle_connection_message(connection, message)
54
- type = message[:type]
55
-
56
- case type
57
- when 'welcome'
58
- subscribe(connection)
59
- when 'confirm_subscription'
60
- on_subscribed
61
- end
62
- end
63
-
64
- def handle_channel_message(connection, message)
65
- type = message[:type]
66
-
67
- case type
68
- when 'output'
69
- print message[:message]
70
- when 'worker_done'
71
- puts ''
72
- connection.close
73
- end
74
- end
75
-
76
- def subscribe(connection)
77
- content =
78
- {
79
- command: :subscribe,
80
- identifier: {
81
- channel: @channel
82
- }.to_json
83
- }
84
- connection.write(content.to_json)
85
- connection.flush
86
- end
87
-
88
- def on_subscribed
89
- response = http_connection.post("/api/neh/o") do |req|
90
- req.body = {
91
- message: @message,
92
- token:
93
- }.to_json
94
-
95
- req.headers['Content-Type'] = 'application/json'
96
- end
97
-
98
- body = JSON.parse response.body
99
- puts body['message'] if debug_mode?
100
- end
101
-
102
- def http_connection
103
- Faraday.new(url: "#{protocol}://#{@endpoint.hostname}:#{@endpoint.port}") do |faraday|
104
- faraday.adapter Faraday.default_adapter
105
- faraday.headers['Authorization'] = "Bearer #{token}"
106
- end
107
- end
108
-
109
- def protocol
110
- @endpoint.secure? ? 'https' : 'http'
111
- end
112
-
113
- def debug_mode?
114
- ENV['NEH_DEBUG'] == 'true'
3
+ module Neh::Cli
4
+ class O < Base
115
5
  end
116
6
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Neh
4
+ module Cli
5
+ class Version
6
+ def execute
7
+ puts "neh version #{Neh::VERSION}"
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/neh/cli.rb CHANGED
@@ -5,4 +5,6 @@ require 'neh'
5
5
  module Neh::Cli
6
6
  end
7
7
 
8
+ require_relative 'cli/base'
8
9
  require_relative 'cli/o'
10
+ require_relative 'cli/decache'
data/lib/neh/thor.rb CHANGED
@@ -4,8 +4,21 @@ require 'thor'
4
4
 
5
5
  require_relative 'cli'
6
6
  require_relative 'cli/o'
7
+ require_relative 'cli/version'
7
8
 
8
9
  class Neh::Thor < Thor
10
+ map %w[--version -v] => :version
11
+
12
+ desc 'version', 'Displays the current version of the application.'
13
+ def version
14
+ Neh::Cli::Version.new.execute
15
+ end
16
+
17
+ desc 'decache', 'Deletes the session cache with the LLM AI so far.'
18
+ def decache(*)
19
+ Neh::Cli::Decache.new(*, options:).execute
20
+ end
21
+
9
22
  desc 'o', 'This is the most standard command you can use to query an LLM AI.'
10
23
  def o(*)
11
24
  Neh::Cli::O.new(*, options:).execute
data/lib/neh/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Neh
4
- VERSION = "0.0.10"
4
+ VERSION = "0.0.12"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atsushi Ishida
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-01 00:00:00.000000000 Z
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-io
@@ -84,7 +84,10 @@ files:
84
84
  - exe/neh
85
85
  - lib/neh.rb
86
86
  - lib/neh/cli.rb
87
+ - lib/neh/cli/base.rb
88
+ - lib/neh/cli/decache.rb
87
89
  - lib/neh/cli/o.rb
90
+ - lib/neh/cli/version.rb
88
91
  - lib/neh/thor.rb
89
92
  - lib/neh/version.rb
90
93
  - sig/neh.rbs
@@ -95,7 +98,7 @@ metadata:
95
98
  source_code_uri: https://github.com/gipcompany/neh
96
99
  changelog_uri: https://github.com/gipcompany/neh/blob/main/CHANGELOG.md
97
100
  rubygems_mfa_required: 'true'
98
- post_install_message:
101
+ post_install_message:
99
102
  rdoc_options: []
100
103
  require_paths:
101
104
  - lib
@@ -110,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
113
  - !ruby/object:Gem::Version
111
114
  version: '0'
112
115
  requirements: []
113
- rubygems_version: 3.5.14
114
- signing_key:
116
+ rubygems_version: 3.4.10
117
+ signing_key:
115
118
  specification_version: 4
116
119
  summary: CLI client for AI with large language models
117
120
  test_files: []