Sha256: 3733da03fb2c2a56e7abaf0bc82b924613cf018d5e244bf21a11eded1997f412

Contents?: true

Size: 1.58 KB

Versions: 22

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

RSpec.describe Ollama::Commands::Embed do
  it 'can be instantiated' do
    embed = described_class.new(
      model: 'all-minilm',
      input: 'Why is the sky blue?',
    )
    expect(embed).to be_a described_class
  end

  it 'can be converted to JSON' do
    embed = described_class.new(
      model: 'all-minilm',
      options: Ollama::Options.new(num_ctx: 666),
      input: 'Why is the sky blue?'
    )
    expect(embed.as_json).to include(
      model: 'all-minilm', input: 'Why is the sky blue?',
    )
    expect(embed.to_json).to eq(
      '{"model":"all-minilm","input":"Why is the sky blue?","options":{"num_ctx":666},"stream":false}'
    )
  end

  it 'can be converted to JSON with array input' do
    embed = described_class.new(
      model: 'all-minilm',
      input: [ 'Why is the sky blue?', 'Why is the grass green?' ],
    )
    expect(embed.as_json).to include(
      model: 'all-minilm', input: [ 'Why is the sky blue?', 'Why is the grass green?' ],
    )
    expect(embed.to_json).to eq(
      '{"model":"all-minilm","input":["Why is the sky blue?","Why is the grass green?"],"stream":false}'
    )
  end


  it 'can perform' do
    embed = described_class.new(
      model: 'all-minilm',
      input: 'Why is the sky blue?'
    )
    embed.client = ollama = double('Ollama::Client')
    expect(ollama).to receive(:request).
      with(
        method: :post, path: '/api/embed', handler: Ollama::Handlers::NOP, stream: false,
        body: '{"model":"all-minilm","input":"Why is the sky blue?","stream":false}'
      )
    embed.perform(Ollama::Handlers::NOP)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ollama-ruby-0.16.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.15.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.14.1 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.14.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.13.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.12.1 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.12.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.11.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.10.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.9.3 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.9.2 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.9.1 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.9.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.8.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.7.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.6.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.5.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.4.0 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.3.2 spec/ollama/commands/embed_spec.rb
ollama-ruby-0.3.1 spec/ollama/commands/embed_spec.rb