Class: EmbeddingUtil::RuntimeCommand
- Inherits:
-
Object
- Object
- EmbeddingUtil::RuntimeCommand
- Defined in:
- lib/embedding_util/runtime_command.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#server_model ⇒ Object
readonly
Returns the value of attribute server_model.
Class Method Summary collapse
- .available?(runtime) ⇒ Boolean
- .command_path(command) ⇒ Object
- .normalize_runtime(runtime) ⇒ Object
- .resolve(runtime) ⇒ Object
Instance Method Summary collapse
- #argv ⇒ Object
- #detached_server? ⇒ Boolean
-
#initialize(runtime:, server_model:, host:, port:) ⇒ RuntimeCommand
constructor
A new instance of RuntimeCommand.
- #label ⇒ Object
- #server_name ⇒ Object
- #stop_argv ⇒ Object
- #stop_argvs ⇒ Object
Constructor Details
#initialize(runtime:, server_model:, host:, port:) ⇒ RuntimeCommand
Returns a new instance of RuntimeCommand.
7 8 9 10 11 12 |
# File 'lib/embedding_util/runtime_command.rb', line 7 def initialize(runtime:, server_model:, host:, port:) @runtime = self.class.normalize_runtime(runtime) @server_model = server_model @host = host @port = port end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/embedding_util/runtime_command.rb', line 5 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/embedding_util/runtime_command.rb', line 5 def port @port end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
5 6 7 |
# File 'lib/embedding_util/runtime_command.rb', line 5 def runtime @runtime end |
#server_model ⇒ Object (readonly)
Returns the value of attribute server_model.
5 6 7 |
# File 'lib/embedding_util/runtime_command.rb', line 5 def server_model @server_model end |
Class Method Details
.available?(runtime) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/embedding_util/runtime_command.rb', line 14 def self.available?(runtime) case normalize_runtime(runtime) when :auto available?(:ramalama) || available?(:llama_server) when :ramalama !!command_path("ramalama") when :llama_server !!command_path("llama-server") else false end end |
.command_path(command) ⇒ Object
37 38 39 |
# File 'lib/embedding_util/runtime_command.rb', line 37 def self.command_path(command) ENV.fetch("PATH", "").split(File::PATH_SEPARATOR).map { |dir| File.join(dir, command) }.find { |path| File.executable?(path) && !File.directory?(path) } end |
.normalize_runtime(runtime) ⇒ Object
41 42 43 |
# File 'lib/embedding_util/runtime_command.rb', line 41 def self.normalize_runtime(runtime) runtime.to_s.tr("-", "_").to_sym end |
.resolve(runtime) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/embedding_util/runtime_command.rb', line 27 def self.resolve(runtime) requested = normalize_runtime(runtime) return requested unless requested == :auto return :ramalama if available?(:ramalama) return :llama_server if available?(:llama_server) :auto end |
Instance Method Details
#argv ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/embedding_util/runtime_command.rb', line 45 def argv case runtime when :ramalama then ramalama_argv when :llama_server then llama_server_argv else raise UnsupportedProviderError, "no supported local runtime found; install ramalama or llama-server" end end |
#detached_server? ⇒ Boolean
57 58 59 |
# File 'lib/embedding_util/runtime_command.rb', line 57 def detached_server? runtime == :ramalama end |
#label ⇒ Object
53 54 55 |
# File 'lib/embedding_util/runtime_command.rb', line 53 def label runtime == :llama_server ? "llama-server" : runtime.to_s end |
#server_name ⇒ Object
77 78 79 |
# File 'lib/embedding_util/runtime_command.rb', line 77 def server_name "embedding-util-#{server_model.name}".tr("_", "-") end |
#stop_argv ⇒ Object
61 62 63 64 65 |
# File 'lib/embedding_util/runtime_command.rb', line 61 def stop_argv return unless detached_server? stop_argvs.first end |
#stop_argvs ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/embedding_util/runtime_command.rb', line 67 def stop_argvs return [] unless detached_server? [ ["ramalama", "stop", server_name], ["podman", "stop", "--time", "0", server_name], ["docker", "stop", server_name] ].select { |argv| self.class.command_path(argv.first) } end |