neh 0.0.11 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neh/cli/base.rb +127 -0
- data/lib/neh/cli/decache.rb +6 -0
- data/lib/neh/cli/o.rb +5 -109
- data/lib/neh/cli.rb +2 -0
- data/lib/neh/thor.rb +5 -0
- data/lib/neh/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c3f44261ded942a8b71b5220b9090665c7bab7a421cad3679021b0532659bec
|
4
|
+
data.tar.gz: 5933563a6faface0525a0e09db270fc110a5701124e31f64fed68d21c293d27c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c937fce4a966a8862dfa7a49a6559384d0ec2d4cc310d3953a37930b70e61cc2cd950945282600980b79c6f548e388650c5bbb0d44f85c4494963e33d5f55412
|
7
|
+
data.tar.gz: f916960510c1afee4da69f1769e80d5f3fcf564dbe327cc25f4380df9c1f24b281ca4a908c12da602696358bd44883dad74b5b9c5911c7933836a2d967df823f
|
data/lib/neh/cli/base.rb
ADDED
@@ -0,0 +1,127 @@
|
|
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
|
+
require 'active_support/all'
|
13
|
+
|
14
|
+
class Neh::Cli::Base
|
15
|
+
def initialize(*args, options:)
|
16
|
+
@message = args.join(' ')
|
17
|
+
|
18
|
+
@options = options
|
19
|
+
server_host = ENV.fetch('NEH_SERVER_HOST', 'yoryo.gipcompany.com')
|
20
|
+
server_port = ENV.fetch('NEH_SERVER_PORT', 443)
|
21
|
+
@channel = 'LargeLanguageModelQueryChannel'
|
22
|
+
|
23
|
+
url = "ws://#{server_host}:#{server_port}/cable"
|
24
|
+
@endpoint = Async::HTTP::Endpoint.parse(url)
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute
|
28
|
+
Async do |_task|
|
29
|
+
Async::WebSocket::Client.connect(@endpoint, headers: { 'Authorization' => "Bearer #{token}" }) do |connection|
|
30
|
+
while (message = connection.read)
|
31
|
+
parsed_message =
|
32
|
+
JSON.parse(message, symbolize_names: true)
|
33
|
+
|
34
|
+
on_receive(connection, parsed_message)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def token
|
43
|
+
ENV.fetch('NEH_PERSONAL_ACCESS_TOKEN')
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_receive(connection, message)
|
47
|
+
if message[:type]
|
48
|
+
handle_connection_message(connection, message)
|
49
|
+
else
|
50
|
+
handle_channel_message(connection, message[:message])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def handle_connection_message(connection, message)
|
55
|
+
type = message[:type]
|
56
|
+
|
57
|
+
case type
|
58
|
+
when 'welcome'
|
59
|
+
subscribe(connection)
|
60
|
+
when 'confirm_subscription'
|
61
|
+
on_subscribed
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def handle_channel_message(connection, message)
|
66
|
+
type = message[:type]
|
67
|
+
|
68
|
+
case type
|
69
|
+
when 'output'
|
70
|
+
print message[:message]
|
71
|
+
when 'worker_done'
|
72
|
+
close(connection)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def close(connection)
|
77
|
+
connection.close
|
78
|
+
end
|
79
|
+
|
80
|
+
def subscribe(connection)
|
81
|
+
content =
|
82
|
+
{
|
83
|
+
command: :subscribe,
|
84
|
+
identifier: {
|
85
|
+
channel: @channel
|
86
|
+
}.to_json
|
87
|
+
}
|
88
|
+
connection.write(content.to_json)
|
89
|
+
connection.flush
|
90
|
+
end
|
91
|
+
|
92
|
+
def on_subscribed
|
93
|
+
response = http_connection.post("/api/neh/#{command}") do |req|
|
94
|
+
req.body = {
|
95
|
+
message: @message,
|
96
|
+
token:
|
97
|
+
}.to_json
|
98
|
+
|
99
|
+
req.headers['Content-Type'] = 'application/json'
|
100
|
+
end
|
101
|
+
|
102
|
+
body = JSON.parse response.body
|
103
|
+
message = body['message']
|
104
|
+
puts message if message.present?
|
105
|
+
end
|
106
|
+
|
107
|
+
def command
|
108
|
+
raise NotImplementedError if instance_of?(Neh::Cli::Base)
|
109
|
+
|
110
|
+
unless self.class.ancestors.include?(Neh::Cli::Base)
|
111
|
+
raise NotImplementedError, 'command method must be implemented in subclasses'
|
112
|
+
end
|
113
|
+
|
114
|
+
self.class.name.demodulize.downcase
|
115
|
+
end
|
116
|
+
|
117
|
+
def http_connection
|
118
|
+
Faraday.new(url: "#{protocol}://#{@endpoint.hostname}:#{@endpoint.port}") do |faraday|
|
119
|
+
faraday.adapter Faraday.default_adapter
|
120
|
+
faraday.headers['Authorization'] = "Bearer #{token}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def protocol
|
125
|
+
@endpoint.secure? ? 'https' : 'http'
|
126
|
+
end
|
127
|
+
end
|
data/lib/neh/cli/o.rb
CHANGED
@@ -1,116 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
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'
|
3
|
+
module Neh::Cli
|
4
|
+
class O < Base
|
5
|
+
private
|
12
6
|
|
13
|
-
|
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'
|
7
|
+
def close(connection)
|
71
8
|
puts ''
|
72
|
-
|
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'
|
9
|
+
super
|
96
10
|
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'
|
115
11
|
end
|
116
12
|
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,15 +1,29 @@
|
|
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.13
|
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
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: async-io
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +98,8 @@ files:
|
|
84
98
|
- exe/neh
|
85
99
|
- lib/neh.rb
|
86
100
|
- lib/neh/cli.rb
|
101
|
+
- lib/neh/cli/base.rb
|
102
|
+
- lib/neh/cli/decache.rb
|
87
103
|
- lib/neh/cli/o.rb
|
88
104
|
- lib/neh/cli/version.rb
|
89
105
|
- lib/neh/thor.rb
|