Module: L::Embeddings
- Defined in:
- lib/lammy/embeddings.rb
Instance Method Summary collapse
Instance Method Details
#handle_v(method_name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lammy/embeddings.rb', line 9 def handle_v(method_name) settings = @next_v_settings @next_v_settings = nil # Unbind the original method original_method = instance_method(method_name) # Redefine the method define_method(method_name) do |*args, &block| # # Initialize chunking settings # @chunk_by_size = nil # # Make `chunk_by_size` method available within the instance # define_singleton_method(:chunk_by_size) do |size| # @chunk_by_size = size # end # Call the original method to get the input input = original_method.bind(self).call(*args, &block) # # Tokenize the input # if @chunk_by_size.blank? # input = [ input ] # else # tokenizer = Tokenizers.from_pretrained("bert-base-cased") # input = tokenizer.encode(input).tokens # end input = [input] case settings[:model] when *OpenAI::EMBEDDINGS client = OpenAI.new(settings) client.(input) else raise "Unsupported model: #{settings[:model]}" end end end |
#v(**kwargs) ⇒ Object
5 6 7 |
# File 'lib/lammy/embeddings.rb', line 5 def v(**kwargs) @next_v_settings = kwargs end |