Class: EmbeddingUtil::CLI
- Inherits:
-
Thor
- Object
- Thor
- EmbeddingUtil::CLI
- Defined in:
- lib/embedding_util/cli.rb
Constant Summary collapse
- CONFIG_OPTIONS =
{ profile: :to_sym.to_proc, runtime: ->(value) { RuntimeCommand.normalize_runtime(value) }, endpoint: ->(value) { value }, embedding_endpoint: ->(value) { value }, reranker_endpoint: ->(value) { value }, timeout: ->(value) { value }, startup_timeout: ->(value) { value }, shutdown_idle: :to_i.to_proc, reranker_ubatch_size: :to_i.to_proc, reranker_max_ubatch_size: :to_i.to_proc, ramalama_device: ->(value) { value }, verbose: ->(value) { value } }.freeze
Instance Method Summary collapse
- #embed(text) ⇒ Object
- #profiles ⇒ Object
- #rerank(query, *documents) ⇒ Object
- #serve ⇒ Object
- #support ⇒ Object
Instance Method Details
#embed(text) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/embedding_util/cli.rb', line 57 def (text) puts JSON.generate(EmbeddingUtil.(text)) rescue Error => e abort e. end |
#profiles ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/embedding_util/cli.rb', line 48 def profiles EmbeddingUtil.profiles.each do |profile| puts profile.name puts " embedding: #{profile..fetch(:repo)} / #{profile..fetch(:file)}" puts " reranker: #{profile.reranker.fetch(:repo)} / #{profile.reranker.fetch(:file)}" end end |
#rerank(query, *documents) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/embedding_util/cli.rb', line 65 def rerank(query, *documents) raise Error, "provide at least one document to rerank" if documents.empty? results = EmbeddingUtil.rerank(query, documents).map do |result| { index: result.index, document: result.document, score: result.score, metadata: result. } end puts JSON.pretty_generate(results) rescue Error => e abort e. end |
#serve ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/embedding_util/cli.rb', line 87 def serve ServerManager.new(config: EmbeddingUtil.configuration).serve( model: [:model], runtime: [:runtime] || EmbeddingUtil.configuration.runtime, shutdown_idle: [:shutdown_idle]&.to_i, host: [:host], port: [:port]&.to_i ) rescue Error => e abort e. rescue Interrupt exit 130 end |
#support ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/embedding_util/cli.rb', line 37 def support EmbeddingUtil.support.each do |item| status = item.fetch(:supported) ? "supported" : "not supported" puts "#{item.fetch(:provider)}: #{status}" puts " embedding_endpoint: #{item.fetch(:embedding_endpoint)}" if item[:embedding_endpoint] puts " reranker_endpoint: #{item.fetch(:reranker_endpoint)}" if item[:reranker_endpoint] end end |