Sha256: 073a4848a97c83e7468d8eb9bc8f790a3fa55da37f75ab90e6c053cc51c32fa7

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby
# examples/text.rb

require_relative 'common'


###################################
## Working with Ollama

# This is the default configuration which returns
# text content from the client.
#
AiClient.configure do |o|
  o.return_raw = false
end

title "Using Mistral model with Ollama locally"

ollama_client = AiClient.new('mistral', provider: :ollama)

puts "\nModel: mistral  Provider: Ollama (local)"
result = ollama_client.chat('Hello, how are you?')
puts result

puts "\nRaw response:"
puts ollama_client.response.pretty_inspect
puts



###############################################################
## Lets look an generic configurations based upon model name ##
###############################################################

models  = [
  'gpt-3.5-turbo',        # OpenAI
  'claude-2.1',           # Anthropic
  'gemini-1.5-flash',     # Google
  'mistral-large-latest', # Mistral - La Platform
]
clients = []

models.each do |model|
  clients << AiClient.new(model)
end


title "Default Configuration Response to 'hello'"

clients.each do |c|
  puts "\nModel: #{c.model}  Provider: #{c.provider}"
  begin
    response = c.chat('hello')
    puts response
  rescue => e
    puts e
  end
end

###################################

AiClient.configure do |o|
  o.return_raw = true
end

raw_clients = []

models.each do |model|
  raw_clients << AiClient.new(model)
end

puts
title "Raw Configuration Response to 'hello'"

raw_clients.each do |c|
  puts "\nModel: #{c.model}  Provider: #{c.provider}"
  begin
    result = c.chat('hello')
    puts result.pretty_inspect
  rescue => e
    puts e
  end
end

puts

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ai_client-0.4.1 examples/text.rb
ai_client-0.4.0 examples/text.rb
ai_client-0.3.1 examples/text.rb
ai_client-0.3.0 examples/text.rb
ai_client-0.2.5 examples/text.rb
ai_client-0.2.4 examples/text.rb
ai_client-0.2.3 examples/text.rb
ai_client-0.2.2 examples/text.rb