-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
231 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'omniai/anthropic' | ||
|
||
CLIENT = OmniAI::Anthropic::Client.new | ||
|
||
CAT_URL = 'https://images.unsplash.com/photo-1472491235688-bdc81a63246e?q=80&w=1024&h=1024&fit=crop&fm=jpg' | ||
DOG_URL = 'https://images.unsplash.com/photo-1517849845537-4d257902454a?q=80&w=1024&h=1024&fit=crop&fm=jpg' | ||
|
||
CLIENT.chat(stream: $stdout) do |prompt| | ||
prompt.system('You are a helpful biologist with an expertise in animals that responds with the latin names.') | ||
prompt.user do |message| | ||
message.text('What animals are in the attached photos?') | ||
message.url(CAT_URL, 'image/jpeg') | ||
message.url(DOG_URL, 'image/jpeg') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'omniai/mistral' | ||
|
||
CLIENT = OmniAI::Mistral::Client.new | ||
|
||
Entry = Data.define(:text, :embedding) do | ||
def initialize(text:) | ||
super(text:, embedding: CLIENT.embed(text).embedding) | ||
end | ||
end | ||
|
||
ENTRIES = [ | ||
Entry.new(text: 'John is a musician.'), | ||
Entry.new(text: 'Paul is a plumber.'), | ||
Entry.new(text: 'George is a teacher.'), | ||
Entry.new(text: 'Ringo is a doctor.'), | ||
].freeze | ||
|
||
def search(query) | ||
embedding = CLIENT.embed(query).embedding | ||
|
||
results = ENTRIES.sort_by do |data| | ||
Math.sqrt(data.embedding.zip(embedding).map { |a, b| (a - b)**2 }.reduce(:+)) | ||
end | ||
|
||
puts "'#{query}': '#{results.first.text}'" | ||
end | ||
|
||
search('What does George do?') | ||
search('Who is a doctor?') | ||
search('Who do you call to fix a toilet?') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'omniai/openai' | ||
|
||
CLIENT = OmniAI::OpenAI::Client.new | ||
|
||
File.open(File.join(__dir__, 'audio.wav'), 'rb') do |file| | ||
transcription = CLIENT.transcribe(file) | ||
puts(transcription.text) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'omniai/openai' | ||
|
||
CLIENT = OmniAI::OpenAI::Client.new | ||
|
||
File.open(File.join(__dir__, 'audio.wav'), 'wb') do |file| | ||
CLIENT.speak('Sally sells seashells by the seashore.', format: OmniAI::Speak::Format::WAV) do |chunk| | ||
file << chunk | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'omniai/google' | ||
|
||
CLIENT = OmniAI::Google::Client.new | ||
|
||
TOOL = OmniAI::Tool.new( | ||
proc { |location:, unit: 'celsius'| "#{rand(20..50)}° #{unit} in #{location}" }, | ||
name: 'Weather', | ||
description: 'Lookup the weather in a location', | ||
parameters: OmniAI::Tool::Parameters.new( | ||
properties: { | ||
location: OmniAI::Tool::Property.string(description: 'e.g. Toronto'), | ||
unit: OmniAI::Tool::Property.string(enum: %w[celcius fahrenheit]), | ||
}, | ||
required: %i[location] | ||
) | ||
) | ||
|
||
completion = CLIENT.chat(tools: [TOOL]) do |prompt| | ||
prompt.user do |message| | ||
message.text('What is the weather in "London" in celcius and "Seattle" in fahrenheit?') | ||
end | ||
end | ||
|
||
puts(completion.text) |