neh 0.0.2 → 0.0.4

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: 3cf60c744f72e9d315e2f5f05c3d4d5278b0861fa76cee05a0fef9bfb19b8abe
4
- data.tar.gz: 6cf8a7ce75f55f56d745e6c980185a5ef9c688ffad6f02483a1b4af54e885bce
3
+ metadata.gz: c047eb9e56275718ff7a63a6975df93fb0500ec77f894584f44a7c343978dab2
4
+ data.tar.gz: 2d87c9c0f83b67bc6611bfc192d27ac45b55791e2101cb1acb75c7491db76632
5
5
  SHA512:
6
- metadata.gz: 87c88a52b19c7fec314f7eecf28b5570574a012fb4f21673587d374d363482da883200bac0ec8315fe65f8ced90657d795aa8431b0b94dbb41e4eb11424ada47
7
- data.tar.gz: 8b6dab176eff9508e8a9d64424badc473165c08fb93a1b351a8b9426759a75cb61aaff4353873345f0f6820a434a4e6ecc995c6e1d2f8bb472500a7c3261c0a6
6
+ metadata.gz: 4c5b963cc9a2b129c030dfb840d8916abfb06b61599734e9677318fb4c79d02acff16c2abe31d05edc0f6fd8111d9e8e16f5992bda88a4a0bc7fd5be9faa86e1
7
+ data.tar.gz: 0d319c601228111049f649741b5b7a80c0598b0841c990a4bb5aad0c4ca9a738943178b23e9db44b5cc9ee7f595707f368745bc41a62995f3357d71617fa1cd8
data/.rubocop.yml CHANGED
@@ -1,8 +1,14 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.0
2
+ TargetRubyVersion: <%= File.read(File.expand_path('../.ruby-version', __FILE__)).strip %>
3
+ NewCops: enable
3
4
 
5
+ Metrics/MethodLength:
6
+ Max: 20
7
+ Style/ClassAndModuleChildren:
8
+ Enabled: false
9
+ Style/Documentation:
10
+ Enabled: false
4
11
  Style/StringLiterals:
5
- EnforcedStyle: double_quotes
6
-
12
+ Enabled: false
7
13
  Style/StringLiteralsInInterpolation:
8
- EnforcedStyle: double_quotes
14
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/README.md CHANGED
@@ -1,31 +1,6 @@
1
- # Neh
1
+ # neh
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Check connectivity from the client to the server.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/neh`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- ## Installation
8
-
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
-
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
-
29
- ## Contributing
30
-
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/neh.
5
+ $ bundle exec neh o
6
+ Worker Progress ====================== 5/5 100.00%
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
data/exe/neh CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "neh"
4
+ require "neh/thor"
5
5
 
6
- puts Neh.greet
6
+ Neh::Thor.start(ARGV)
data/lib/neh/cli/o.rb ADDED
@@ -0,0 +1,116 @@
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::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'
115
+ end
116
+ end
data/lib/neh/cli.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'neh'
4
+
5
+ module Neh::Cli
6
+ end
7
+
8
+ require_relative 'cli/o'
data/lib/neh/thor.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ require_relative 'cli'
6
+ require_relative 'cli/o'
7
+
8
+ class Neh::Thor < Thor
9
+ desc 'o', 'This is the most standard command you can use to query an LLM AI.'
10
+ def o(*)
11
+ Neh::Cli::O.new(*, options:).execute
12
+ end
13
+ end
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.2"
4
+ VERSION = "0.0.4"
5
5
  end
data/lib/neh.rb CHANGED
@@ -2,15 +2,5 @@
2
2
 
3
3
  require_relative "neh/version"
4
4
 
5
- # Neh module provides a sample greet method.
6
5
  module Neh
7
- # Error class is a standard error class used within the Neh module.
8
- class Error < StandardError; end
9
-
10
- # The `greet` method returns a greeting message from the Neh module.
11
- #
12
- # @return [String] Greeting message
13
- def self.greet
14
- "Hello from the neh gem!"
15
- end
16
6
  end
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
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-05-27 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-io
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.43.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.43.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: async-websocket
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.26.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.26.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
13
69
  description: Lightweight CLI client for interacting with AI using large language models
14
70
  (LLM)
15
71
  email:
@@ -21,11 +77,15 @@ extra_rdoc_files: []
21
77
  files:
22
78
  - ".rspec"
23
79
  - ".rubocop.yml"
80
+ - ".ruby-version"
24
81
  - CHANGELOG.md
25
82
  - README.md
26
83
  - Rakefile
27
84
  - exe/neh
28
85
  - lib/neh.rb
86
+ - lib/neh/cli.rb
87
+ - lib/neh/cli/o.rb
88
+ - lib/neh/thor.rb
29
89
  - lib/neh/version.rb
30
90
  - sig/neh.rbs
31
91
  homepage: https://github.com/gipcompany/neh
@@ -34,22 +94,23 @@ metadata:
34
94
  homepage_uri: https://github.com/gipcompany/neh
35
95
  source_code_uri: https://github.com/gipcompany/neh
36
96
  changelog_uri: https://github.com/gipcompany/neh/blob/main/CHANGELOG.md
97
+ rubygems_mfa_required: 'true'
37
98
  post_install_message:
38
99
  rdoc_options: []
39
100
  require_paths:
40
101
  - lib
41
102
  required_ruby_version: !ruby/object:Gem::Requirement
42
103
  requirements:
43
- - - ">="
104
+ - - "~>"
44
105
  - !ruby/object:Gem::Version
45
- version: 3.0.0
106
+ version: 3.2.2
46
107
  required_rubygems_version: !ruby/object:Gem::Requirement
47
108
  requirements:
48
109
  - - ">="
49
110
  - !ruby/object:Gem::Version
50
111
  version: '0'
51
112
  requirements: []
52
- rubygems_version: 3.5.10
113
+ rubygems_version: 3.5.14
53
114
  signing_key:
54
115
  specification_version: 4
55
116
  summary: CLI client for AI with large language models