summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricebaker <icebaker@proton.me>2023-05-13 11:26:58 -0300
committericebaker <icebaker@proton.me>2023-05-13 11:26:58 -0300
commit7da6076e7448bea2776749af5d937fc841b5682d (patch)
tree768bcfe401b659b231e445f252e296e201e2589d
parent867f7bd1eaf4801cd894d067a39df62ac4249a27 (diff)
debugging
-rw-r--r--README.md22
-rw-r--r--components/storage.rb2
-rw-r--r--controllers/instance.rb19
-rw-r--r--controllers/interfaces/cli.rb30
-rw-r--r--controllers/session.rb2
-rw-r--r--ports/dsl/nano-bots.rb6
6 files changed, 61 insertions, 20 deletions
diff --git a/README.md b/README.md
index 867259d..7c45ee9 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,8 @@ https://user-images.githubusercontent.com/113217272/237840989-1e29a5cc-6644-48d0
- [Command Line](#command-line)
- [Library](#library)
- [Cartridges](#cartridges)
+- [Providers](#providers)
+- [Debugging](#debugging)
- [Development](#development)
- [Publish to RubyGems](#publish-to-rubygems)
@@ -94,8 +96,8 @@ Start playing:
nb - - eval "hello"
nb - - repl
-nb cartridges/assistant.yml - repl
nb cartridges/assistant.yml - eval "hello"
+nb cartridges/assistant.yml - repl
```
## Usage
@@ -164,6 +166,14 @@ require 'securerandom'
SecureRandom.hex # => 6ea6c43c42a1c076b1e3c36fa349ac2c
```
+### Debugging
+
+```sh
+nb - STATE-KEY state
+nb cartridge.yml STATE-KEY state
+nb cartridge.yml - cartridge
+```
+
### Library
To use it as a library:
@@ -217,6 +227,16 @@ provider:
Check the Nano Bots specification to learn more about [how to build cartridges](https://icebaker.github.io/nano-bots/#/README?id=cartridges).
+## Providers
+
+Currently supported providers:
+
+- [ ] [Vicuna](https://github.com/lm-sys/FastChat)
+- [x] [Open AI](https://platform.openai.com/docs/api-reference)
+- [ ] [Google PaLM](https://developers.generativeai.google/)
+- [ ] [Alpaca](https://github.com/tatsu-lab/stanford_alpaca)
+- [ ] [LLaMA](https://github.com/facebookresearch/llama)
+
## Development
```bash
diff --git a/components/storage.rb b/components/storage.rb
index 3d3f58d..d46455f 100644
--- a/components/storage.rb
+++ b/components/storage.rb
@@ -19,7 +19,7 @@ module NanoBot
path = "#{path.sub(%r{/$}, '')}/ruby-nano-bots/#{cartridge[:meta][:author].to_slug.normalize}"
path = "#{path}/#{cartridge[:meta][:name].to_slug.normalize}"
- path = "#{path}/#{cartridge[:meta][:version].to_s.gsub('.', '-').to_slug.normalize}/#{key.to_slug.normalize}"
+ path = "#{path}/#{cartridge[:meta][:version].to_s.gsub('.', '-').to_slug.normalize}/#{key}"
path = "#{path}/state.json"
FileUtils.mkdir_p(File.dirname(path))
diff --git a/controllers/instance.rb b/controllers/instance.rb
index 243e266..b22a785 100644
--- a/controllers/instance.rb
+++ b/controllers/instance.rb
@@ -22,8 +22,12 @@ module NanoBot
@session = Session.new(provider:, cartridge: @cartridge, state:, stream: @stream)
end
- def debug
- @session.debug
+ def cartridge
+ puts YAML.dump(@safe_cartridge)
+ end
+
+ def state
+ @session.state
end
def eval(input)
@@ -61,12 +65,11 @@ module NanoBot
raise StandardError, "Cartridge file not found: \"#{path}\""
end
- @cartridge = Logic::Helpers::Hash.symbolize_keys(
- YAML.safe_load(
- File.read(elected_path),
- permitted_classes: [Symbol]
- )
- )
+ @cartridge = YAML.safe_load(File.read(elected_path), permitted_classes: [Symbol])
+
+ @safe_cartridge = Marshal.load(Marshal.dump(@cartridge))
+
+ @cartridge = Logic::Helpers::Hash.symbolize_keys(@cartridge)
inject_environment_variables!(@cartridge)
end
diff --git a/controllers/interfaces/cli.rb b/controllers/interfaces/cli.rb
index 92e468b..2a93044 100644
--- a/controllers/interfaces/cli.rb
+++ b/controllers/interfaces/cli.rb
@@ -13,14 +13,30 @@ module NanoBot
puts NanoBot::GEM[:version]
exit
when 'help', '', nil
+ puts ''
puts "Nano Bots #{NanoBot::GEM[:version]}"
- puts ' nb cartridge.yml - eval "Hello"'
+ puts ''
+ puts ' nb - - eval "hello"'
+ puts ' nb - - repl'
+ puts ''
+ puts ' nb cartridge.yml - eval "hello"'
puts ' nb cartridge.yml - repl'
- puts ' nb cartridge.yml - debug'
- puts ' nb cartridge.yml STATE-KEY eval "Hello"'
+ puts ''
+ puts ' nb - STATE-KEY eval "hello"'
+ puts ' nb - STATE-KEY repl'
+ puts ''
+ puts ' nb cartridge.yml STATE-KEY eval "hello"'
puts ' nb cartridge.yml STATE-KEY repl'
- puts ' nb cartridge.yml STATE-KEY debug'
+ puts ''
+ puts ' nb - - cartridge'
+ puts ' nb cartridge.yml - cartridge'
+ puts ''
+ puts ' nb - STATE-KEY state'
+ puts ' nb cartridge.yml STATE-KEY state'
+ puts ''
puts ' nb version'
+ puts ' nb help'
+ puts ''
exit
end
@@ -37,8 +53,10 @@ module NanoBot
bot.eval(params[:input])
when 'repl'
bot.repl
- when 'debug'
- bot.debug
+ when 'state'
+ bot.state
+ when 'cartridge'
+ bot.cartridge
else
raise "TODO: [#{params[:command]}]"
end
diff --git a/controllers/session.rb b/controllers/session.rb
index ad640c8..afaca18 100644
--- a/controllers/session.rb
+++ b/controllers/session.rb
@@ -31,7 +31,7 @@ module NanoBot
end
end
- def debug
+ def state
pp({
state: {
path: @state_path,
diff --git a/ports/dsl/nano-bots.rb b/ports/dsl/nano-bots.rb
index b6f4462..40bed1d 100644
--- a/ports/dsl/nano-bots.rb
+++ b/ports/dsl/nano-bots.rb
@@ -7,7 +7,7 @@ require_relative '../../controllers/instance'
require_relative '../../controllers/interfaces/cli'
module NanoBot
- def self.new(cartridge:, state: '-')
+ def self.new(cartridge: '-', state: '-')
Controllers::Instance.new(cartridge_path: cartridge, state:, stream: StringIO.new)
end
@@ -15,8 +15,8 @@ module NanoBot
Controllers::Interfaces::CLI.handle!
end
- def self.repl(cartridge:, state: '-')
- Controllers::Instance.new(cartridge_path: cartridge, state:).repl
+ def self.repl(cartridge: '-', state: '-')
+ Controllers::Instance.new(cartridge_path: cartridge, state:, stream: $stdout).repl
end
def self.version