neh 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/neh/cli/base.rb +126 -0
- data/lib/neh/cli/decache.rb +6 -0
- data/lib/neh/cli/o.rb +2 -112
- data/lib/neh/cli.rb +2 -0
- data/lib/neh/thor.rb +5 -0
- data/lib/neh/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ee23f077b2167f86dc40dcf5d0f2c1d8d04f806ebf883cb4b926778a549d37c
|
4
|
+
data.tar.gz: 95cf5614fa37ae4abcbddcfdca91bd364580c2aaf4fe73c99d0fdac13799009e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0348653539a6f078c28a17544b5a0ca9119458457774937b1e6cbcf5ec59a8038a36992f03885f0fca7773ad1e975a7241c25471ead5055495ff453cebeeb1e
|
7
|
+
data.tar.gz: f4c05d264f7ec7669d846e83eea18680e0178b0830f5ecfdce5cf0a1898c5cb1190e4bcb3f65b7692a7da18d4df2553977359d4a38d55ccf64cca16599bbe05a
|
data/lib/neh/cli/base.rb
ADDED
@@ -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
|
data/lib/neh/cli/o.rb
CHANGED
@@ -1,116 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
data/lib/neh/cli.rb
CHANGED
data/lib/neh/thor.rb
CHANGED
@@ -14,6 +14,11 @@ class Neh::Thor < Thor
|
|
14
14
|
Neh::Cli::Version.new.execute
|
15
15
|
end
|
16
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
|
+
|
17
22
|
desc 'o', 'This is the most standard command you can use to query an LLM AI.'
|
18
23
|
def o(*)
|
19
24
|
Neh::Cli::O.new(*, options:).execute
|
data/lib/neh/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atsushi Ishida
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
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,6 +84,8 @@ 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
|
88
90
|
- lib/neh/cli/version.rb
|
89
91
|
- lib/neh/thor.rb
|