-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly implement serialize / deserialize
- Loading branch information
Showing
6 changed files
with
80 additions
and
34 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
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
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,49 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/setup' | ||
require 'omniai/openai' | ||
|
||
CLIENT = OmniAI::OpenAI::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 farenheit]), | ||
}, | ||
required: %i[location] | ||
) | ||
) | ||
|
||
def example1(stream: $stdout) | ||
stream.puts '> [USER] Tell me a joke' | ||
response = CLIENT.chat('Tell me a joke') | ||
stream.puts response.text | ||
end | ||
|
||
def example2(stream: $stdout) | ||
stream.puts '> [SYSTEM] Respond in both English and French.' | ||
stream.puts '> [USER] What is the fastest animal?' | ||
CLIENT.chat(stream:) do |prompt| | ||
prompt.system 'Respond in both English and French.' | ||
prompt.user 'What is the fastest animal?' | ||
end | ||
end | ||
|
||
def example3(stream: $stdout) | ||
stream.puts '> [SYSTEM] You are an expert in weather.' | ||
stream.puts '> [USER] What is the weather in "London" in celsius and "Madrid" in fahrenheit?' | ||
response = CLIENT.chat(tools: [TOOL]) do |prompt| | ||
prompt.system 'You are an expert in weather.' | ||
prompt.user 'What is the weather in "London" in celsius and "Madrid" in fahrenheit?' | ||
end | ||
stream.puts response.text | ||
end | ||
|
||
example1 | ||
example2 | ||
example3 |
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
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module OmniAI | ||
module OpenAI | ||
VERSION = '1.7.0' | ||
VERSION = '1.8.0' | ||
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