diff options
author | icebaker <icebaker@proton.me> | 2023-12-14 22:49:06 -0300 |
---|---|---|
committer | icebaker <icebaker@proton.me> | 2023-12-14 22:49:06 -0300 |
commit | e6f0374cc8844d4a053db4e68feee23ffc793d73 (patch) | |
tree | a06163503c7a4f754be1a91bbaaee9adf9e7c7b2 /spec/logic | |
parent | fb96658a1ca4b6e3e0505e7a39f660e1a05b3c6e (diff) |
adding support for google gemini
Diffstat (limited to 'spec/logic')
-rw-r--r-- | spec/logic/providers/google/tools_spec.rb | 78 | ||||
-rw-r--r-- | spec/logic/providers/openai/tools_spec.rb | 7 |
2 files changed, 84 insertions, 1 deletions
diff --git a/spec/logic/providers/google/tools_spec.rb b/spec/logic/providers/google/tools_spec.rb new file mode 100644 index 0000000..149a5c4 --- /dev/null +++ b/spec/logic/providers/google/tools_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'yaml' + +require_relative '../../../../logic/providers/google/tools' + +RSpec.describe NanoBot::Logic::Google::Tools do + context 'tools' do + let(:cartridge) { load_symbolized('cartridges/tools.yml') } + + context 'adapt' do + it 'adapts to Google expected format' do + expect(described_class.adapt(cartridge[:tools][0])).to eq( + { name: 'what-time-is-it', + description: 'Returns the current date and time for a given timezone.', + parameters: { + type: 'object', + properties: { + timezone: { + type: 'string', + description: 'A string representing the timezone that should be used to provide a datetime, following the IANA (Internet Assigned Numbers Authority) Time Zone Database. Examples are "Asia/Tokyo" and "Europe/Paris".' + } + }, + required: ['timezone'] + } } + ) + + expect(described_class.adapt(cartridge[:tools][1])).to eq( + { name: 'get-current-weather', + description: 'Get the current weather in a given location.', + parameters: { + type: 'object', + properties: { location: { type: 'string' }, unit: { type: 'string' } } + } } + ) + + expect(described_class.adapt(cartridge[:tools][2])).to eq( + { name: 'sh', + description: "It has access to computer users' data and can be used to run shell commands, similar to those in a Linux terminal, to extract information. Please be mindful and careful to avoid running dangerous commands on users' computers.", + parameters: { + type: 'object', + properties: { + command: { + type: 'array', + description: 'An array of strings that represents a shell command along with its arguments or options. For instance, `["df", "-h"]` executes the `df -h` command, where each array element specifies either the command itself or an associated argument/option.', + items: { type: 'string' } + } + } + } } + ) + + expect(described_class.adapt(cartridge[:tools][3])).to eq( + { name: 'clock', + description: 'Returns the current date and time.', + parameters: { type: 'object', properties: {} } } + ) + end + end + + context 'prepare' do + let(:tools) { load_symbolized('providers/google/tools.yml') } + + it 'prepare tools to be executed' do + expect(described_class.prepare(cartridge[:tools], tools)).to eq( + [{ name: 'get_current_weather', + label: 'get-current-weather', + type: 'function', + parameters: { location: 'Tokyo, Japan' }, + source: { fennel: "(let [{:location location :unit unit} parameters]\n (.. \"Here is the weather in \" location \", in \" unit \": 35.8°C.\"))\n" } }, + { name: 'what_time_is_it', + label: 'what-time-is-it', + type: 'function', parameters: { timezone: 'local' }, + source: { fennel: "(os.date)\n" } }] + ) + end + end + end +end diff --git a/spec/logic/providers/openai/tools_spec.rb b/spec/logic/providers/openai/tools_spec.rb index 949d097..9757c17 100644 --- a/spec/logic/providers/openai/tools_spec.rb +++ b/spec/logic/providers/openai/tools_spec.rb @@ -78,10 +78,15 @@ RSpec.describe NanoBot::Logic::OpenAI::Tools do expect(described_class.prepare(cartridge[:tools], tools)).to eq( [{ id: 'call_XYZ', name: 'get-current-weather', + label: 'get-current-weather', type: 'function', parameters: { 'location' => 'Tokyo, Japan' }, source: { fennel: "(let [{:location location :unit unit} parameters]\n (.. \"Here is the weather in \" location \", in \" unit \": 35.8°C.\"))\n" } }, - { id: 'call_ZYX', name: 'what-time-is-it', type: 'function', parameters: {}, + { id: 'call_ZYX', + name: 'what-time-is-it', + label: 'what-time-is-it', + type: 'function', + parameters: {}, source: { fennel: "(os.date)\n" } }] ) end |