Sha256: 6132779f69f7ce199a62995129fe06cf11c112d2005f3b48c85648e9d69f574e

Contents?: true

Size: 1.89 KB

Versions: 16

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

RSpec.describe Ollama::Commands::Chat do
  it 'can be instantiated' do
    messages = [
      Ollama::Message.new(role: 'user', content: "Let's play Global Thermonuclear War.")
    ]
    chat = described_class.new(model: 'llama3.1', messages:, stream: true)
    expect(chat).to be_a described_class
  end

  it 'can handle hashes as messages' do
    messages = { role: 'user', content: "Let's play Global Thermonuclear War." }
    chat = described_class.new(model: 'llama3.1', messages:, stream: true)
    expect(chat).to be_a described_class
  end

  it 'can handle arrays of hashes as messages' do
    messages = [
      { role: 'user', content: "Let's play Global Thermonuclear War." }
    ]
    chat = described_class.new(model: 'llama3.1', messages:, stream: true)
    expect(chat).to be_a described_class
  end

  it 'can be converted to JSON' do
    messages = [
      Ollama::Message.new(role: 'user', content: "Let's play Global Thermonuclear War.")
    ]
    chat = described_class.new(model: 'llama3.1', messages:, stream: true)
    expect(chat.as_json).to include(
      model: 'llama3.1', messages: messages.map(&:as_json), stream: true,
    )
    expect(chat.to_json).to eq(
      '{"model":"llama3.1","messages":[{"role":"user","content":"Let\'s play Global Thermonuclear War."}],"stream":true}'
    )
  end

  it 'can perform' do
    messages = [
      Ollama::Message.new(role: 'user', content: "Let's play Global Thermonuclear War.")
    ]
    chat = described_class.new(model: 'llama3.1', messages:, stream: true)
    chat.client = ollama = double('Ollama::Client')
    expect(ollama).to receive(:request).
      with(
        method: :post, path: '/api/chat', handler: Ollama::Handlers::NOP, stream: true,
        body: '{"model":"llama3.1","messages":[{"role":"user","content":"Let\'s play Global Thermonuclear War."}],"stream":true}'
      )
    chat.perform(Ollama::Handlers::NOP)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ollama-ruby-0.12.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.11.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.10.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.9.3 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.9.2 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.9.1 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.9.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.8.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.7.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.6.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.5.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.4.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.3.2 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.3.1 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.3.0 spec/ollama/commands/chat_spec.rb
ollama-ruby-0.2.0 spec/ollama/commands/chat_spec.rb