diff options
author | icebaker <113217272+icebaker@users.noreply.github.com> | 2024-01-10 22:02:42 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 22:02:42 -0300 |
commit | 50677c9b2ab6ce8f6fe232834f139f1e16f0e079 (patch) | |
tree | 866218debc763547818de0099098bc5fe2ae29c7 /spec/logic | |
parent | 819381e7bd3e3ca5d310ad0a29b6925dcfa26720 (diff) | |
parent | aabf3d9b711f66fe4195a8c850856826c7ad5580 (diff) |
Merge pull request #15 from icebaker/ib-markdown
Adding support to Markdown Cartridges
Diffstat (limited to 'spec/logic')
-rw-r--r-- | spec/logic/cartridge/parser_spec.rb | 119 | ||||
-rw-r--r-- | spec/logic/helpers/hash_spec.rb | 17 |
2 files changed, 136 insertions, 0 deletions
diff --git a/spec/logic/cartridge/parser_spec.rb b/spec/logic/cartridge/parser_spec.rb new file mode 100644 index 0000000..8297baa --- /dev/null +++ b/spec/logic/cartridge/parser_spec.rb @@ -0,0 +1,119 @@ +# frozen_string_literal: true + +require_relative '../../../logic/cartridge/parser' + +RSpec.describe NanoBot::Logic::Cartridge::Parser do + context 'markdown' do + context 'default' do + let(:raw) { File.read('spec/data/cartridges/markdown.md') } + + it 'parses markdown cartridge' do + expect(described_class.parse(raw, format: 'md')).to eq( + { meta: { + symbol: '🤖', + name: 'ChatGPT 4 Turbo', + author: 'icebaker', + version: '0.0.1', + license: 'CC0-1.0', + description: 'A helpful assistant.' + }, + behaviors: { interaction: { directive: 'You are a helpful assistant.' } }, + provider: { + id: 'openai', + credentials: { 'access-token': 'ENV/OPENAI_API_KEY' }, + settings: { + user: 'ENV/NANO_BOTS_END_USER', + model: 'gpt-4-1106-preview' + } + } } + ) + end + end + + context 'meta' do + let(:raw) { File.read('spec/data/cartridges/meta.md') } + + it 'parses markdown cartridge' do + expect(described_class.parse(raw, format: 'md')).to eq( + { + meta: { + symbol: '🤖', + name: 'Nano Bot Name', + author: 'Your Name', + description: 'A helpful assistant.', + version: '1.0.0', + license: 'CC0-1.0' + }, + behaviors: { + interaction: { + directive: 'You are a helpful assistant.' + } + } + } + ) + end + end + + context 'tools' do + let(:raw) { File.read('spec/data/cartridges/tools.md') } + + it 'parses markdown cartridge' do + expect(described_class.parse(raw, format: 'md')).to eq( + { meta: { + symbol: '🕛', + name: 'Date and Time', + author: 'icebaker', + version: '0.0.1', + license: 'CC0-1.0', + description: 'A helpful assistant.' + }, + behaviors: { + interaction: { + directive: 'You are a helpful assistant.' + } + }, + provider: { + id: 'openai', + credentials: { 'access-token': 'ENV/OPENAI_API_KEY' }, + settings: { + user: 'ENV/NANO_BOTS_END_USER', + model: 'gpt-4-1106-preview' + } + }, + tools: [ + { name: 'random-number', + description: 'Generates a random number within a given range.', + parameters: { + type: 'object', + properties: { + from: { + type: 'integer', + description: 'The minimum expected number for random generation.' + }, + to: { + type: 'integer', + description: 'The maximum expected number for random generation.' + } + }, + required: %w[from to] + }, + clojure: "(let [{:strs [from to]} parameters]\n (+ from (rand-int (+ 1 (- to from)))))\n" }, + { name: 'date-and-time', + description: 'Returns the current date and time.', + fennel: "(os.date)\n" } + ] } + ) + end + end + + context 'block' do + let(:raw) { File.read('spec/data/cartridges/block.md') } + + it 'parses markdown cartridge' do + expect(described_class.parse(raw, format: 'md')).to eq( + { safety: { functions: { sandboxed: false } } } + ) + end + end + end +end diff --git a/spec/logic/helpers/hash_spec.rb b/spec/logic/helpers/hash_spec.rb index 09012c8..0da92fb 100644 --- a/spec/logic/helpers/hash_spec.rb +++ b/spec/logic/helpers/hash_spec.rb @@ -7,7 +7,24 @@ RSpec.describe NanoBot::Logic::Helpers::Hash do expect(described_class.symbolize_keys({ 'a' => 'b', 'c' => { 'd' => ['e'] } })).to eq( { a: 'b', c: { d: ['e'] } } ) + end + + it 'deep merges' do + expect(described_class.deep_merge( + { a: { x: 1, y: 2 }, b: 3 }, + { a: { y: 99, z: 4 }, c: 5 } + )).to eq( + { a: { x: 1, y: 99, z: 4 }, b: 3, c: 5 } + ) + end + + it 'stringify keys' do + expect(described_class.stringify_keys({ a: 'b', c: { d: [:e] } })).to eq( + { 'a' => 'b', 'c' => { 'd' => [:e] } } + ) + end + it 'fetch a path of keys' do expect(described_class.fetch({ a: 'b', c: { d: ['e'] } }, %i[c d])).to eq( ['e'] ) |