nano-bots 0.1.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +3 -2
- data/Gemfile.lock +38 -23
- data/README.md +90 -10
- data/components/adapter.rb +16 -30
- data/components/embedding.rb +89 -0
- data/components/provider.rb +1 -1
- data/components/providers/openai/tools.rb +101 -0
- data/components/providers/openai.rb +103 -20
- data/components/storage.rb +1 -1
- data/components/stream.rb +6 -1
- data/controllers/cartridges.rb +1 -1
- data/controllers/instance.rb +4 -4
- data/controllers/interfaces/cli.rb +1 -1
- data/controllers/interfaces/tools.rb +104 -0
- data/controllers/security.rb +3 -4
- data/controllers/session.rb +80 -26
- data/docker-compose.example.yml +3 -4
- data/logic/cartridge/adapters.rb +1 -1
- data/logic/cartridge/affixes.rb +1 -1
- data/logic/cartridge/default.rb +2 -2
- data/logic/cartridge/fetch.rb +24 -0
- data/logic/cartridge/interaction.rb +7 -7
- data/logic/cartridge/safety.rb +39 -0
- data/logic/cartridge/tools.rb +53 -0
- data/logic/providers/openai/tools.rb +58 -0
- data/logic/providers/openai.rb +57 -0
- data/nano-bots.gemspec +3 -2
- data/static/cartridges/baseline.yml +1 -1
- data/static/cartridges/default.yml +16 -0
- data/static/fennel/LICENSE +0 -2
- data/static/fennel/fennel.lua +1763 -1871
- data/static/gem.rb +1 -1
- metadata +36 -7
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'fetch'
|
4
|
+
require_relative 'affixes'
|
5
|
+
require_relative 'adapters'
|
6
|
+
|
7
|
+
module NanoBot
|
8
|
+
module Logic
|
9
|
+
module Cartridge
|
10
|
+
module Tools
|
11
|
+
def self.fetch_from_interface(cartridge, interface, action, path)
|
12
|
+
Fetch.cascate(cartridge, [
|
13
|
+
[:interfaces, interface, :tools, action].concat(path),
|
14
|
+
[:interfaces, :tools, action].concat(path),
|
15
|
+
%i[interfaces tools].concat(path)
|
16
|
+
])
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.feedback?(cartridge, interface, action)
|
20
|
+
Fetch.cascate(cartridge, [
|
21
|
+
[:interfaces, interface, :tools, action, :feedback],
|
22
|
+
[:interfaces, :tools, action, :feedback],
|
23
|
+
%i[interfaces tools feedback]
|
24
|
+
])
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.input(cartridge, interface, content)
|
28
|
+
lua = Adapter.expression(cartridge, interface, :input, :lua)
|
29
|
+
fennel = Adapter.expression(cartridge, interface, :input, :fennel)
|
30
|
+
|
31
|
+
prefix = Affixes.get(cartridge, interface, :input, :prefix)
|
32
|
+
suffix = Affixes.get(cartridge, interface, :input, :suffix)
|
33
|
+
|
34
|
+
{ content:, prefix:, suffix:, lua:, fennel: }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.output(cartridge, interface, result, streaming, _finished)
|
38
|
+
if streaming
|
39
|
+
result[:message] = { content: result[:message], lua: nil, fennel: nil }
|
40
|
+
return result
|
41
|
+
end
|
42
|
+
|
43
|
+
lua = Adapter.expression(cartridge, interface, :output, :lua)
|
44
|
+
fennel = Adapter.expression(cartridge, interface, :output, :fennel)
|
45
|
+
|
46
|
+
result[:message] = { content: result[:message], lua:, fennel: }
|
47
|
+
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require_relative '../../helpers/hash'
|
6
|
+
|
7
|
+
module NanoBot
|
8
|
+
module Logic
|
9
|
+
module OpenAI
|
10
|
+
module Tools
|
11
|
+
def self.prepare(cartridge, tools)
|
12
|
+
applies = []
|
13
|
+
|
14
|
+
tools = Marshal.load(Marshal.dump(tools))
|
15
|
+
|
16
|
+
tools.each do |tool|
|
17
|
+
tool = Helpers::Hash.symbolize_keys(tool)
|
18
|
+
|
19
|
+
cartridge.each do |candidate|
|
20
|
+
next unless tool[:function][:name] == candidate[:name]
|
21
|
+
|
22
|
+
source = {}
|
23
|
+
|
24
|
+
source[:clojure] = candidate[:clojure] if candidate[:clojure]
|
25
|
+
source[:fennel] = candidate[:fennel] if candidate[:fennel]
|
26
|
+
source[:lua] = candidate[:lua] if candidate[:lua]
|
27
|
+
|
28
|
+
applies << {
|
29
|
+
id: tool[:id],
|
30
|
+
name: tool[:function][:name],
|
31
|
+
type: 'function',
|
32
|
+
parameters: JSON.parse(tool[:function][:arguments]),
|
33
|
+
source:
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
raise 'missing tool' if applies.size != tools.size
|
39
|
+
|
40
|
+
applies
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.adapt(cartridge)
|
44
|
+
output = {
|
45
|
+
type: 'function',
|
46
|
+
function: {
|
47
|
+
name: cartridge[:name], description: cartridge[:description]
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
output[:function][:parameters] = (cartridge[:parameters] || { type: 'object', properties: {} })
|
52
|
+
|
53
|
+
output
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module NanoBot
|
6
|
+
module Logic
|
7
|
+
module OpenAI
|
8
|
+
def self.prepare_tools(cartridge, tools)
|
9
|
+
applies = []
|
10
|
+
tools.each do |tool|
|
11
|
+
cartridge.each do |candidate|
|
12
|
+
next unless candidate[:type] == 'function' &&
|
13
|
+
tool[:type] == candidate[:type] &&
|
14
|
+
tool[:function][:name] == candidate[:name]
|
15
|
+
|
16
|
+
source = {}
|
17
|
+
|
18
|
+
source[:fennel] = candidate[:fennel] if candidate[:fennel]
|
19
|
+
source[:lua] = candidate[:lua] if candidate[:lua]
|
20
|
+
|
21
|
+
applies << {
|
22
|
+
name: tool[:function][:name],
|
23
|
+
type: candidate[:type],
|
24
|
+
parameters: JSON.parse(tool[:function][:arguments]),
|
25
|
+
source:
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
applies
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.adapt_tool(cartridge)
|
34
|
+
raise 'unsupported tool' if cartridge[:type] != 'function'
|
35
|
+
|
36
|
+
adapted = {
|
37
|
+
type: 'function',
|
38
|
+
function: {
|
39
|
+
name: cartridge[:name], description: cartridge[:description],
|
40
|
+
parameters: { type: 'object', properties: {} }
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
properties = adapted[:function][:parameters][:properties]
|
45
|
+
|
46
|
+
cartridge[:parameters].each do |parameter|
|
47
|
+
key = parameter[:name].to_sym
|
48
|
+
properties[key] = {}
|
49
|
+
properties[key][:type] = parameter[:type] || 'string'
|
50
|
+
properties[key][:description] = parameter[:description] if parameter[:description]
|
51
|
+
end
|
52
|
+
|
53
|
+
adapted
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/nano-bots.gemspec
CHANGED
@@ -32,12 +32,13 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.executables = ['nb']
|
33
33
|
|
34
34
|
spec.add_dependency 'babosa', '~> 2.0'
|
35
|
+
spec.add_dependency 'concurrent-ruby', '~> 1.2', '>= 1.2.2'
|
35
36
|
spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
|
36
|
-
spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.
|
37
|
+
spec.add_dependency 'faraday', '~> 2.7', '>= 2.7.12'
|
37
38
|
spec.add_dependency 'pry', '~> 0.14.2'
|
38
39
|
spec.add_dependency 'rainbow', '~> 3.1', '>= 3.1.1'
|
39
40
|
spec.add_dependency 'rbnacl', '~> 7.1', '>= 7.1.1'
|
40
|
-
spec.add_dependency 'ruby-openai', '~>
|
41
|
+
spec.add_dependency 'ruby-openai', '~> 6.3'
|
41
42
|
spec.add_dependency 'sweet-moon', '~> 0.0.7'
|
42
43
|
|
43
44
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
@@ -1,4 +1,10 @@
|
|
1
1
|
---
|
2
|
+
safety:
|
3
|
+
functions:
|
4
|
+
sandboxed: true
|
5
|
+
tools:
|
6
|
+
confirmable: true
|
7
|
+
|
2
8
|
interfaces:
|
3
9
|
repl:
|
4
10
|
output:
|
@@ -12,6 +18,16 @@ interfaces:
|
|
12
18
|
output:
|
13
19
|
stream: true
|
14
20
|
suffix: "\n"
|
21
|
+
tools:
|
22
|
+
confirming:
|
23
|
+
suffix: ' [yN] '
|
24
|
+
default: 'n'
|
25
|
+
yeses: ['y', 'yes']
|
26
|
+
executing:
|
27
|
+
feedback: false
|
28
|
+
responding:
|
29
|
+
suffix: "\n\n"
|
30
|
+
feedback: true
|
15
31
|
|
16
32
|
provider:
|
17
33
|
settings:
|
data/static/fennel/LICENSE
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright © 2016-2022 Calvin Rose and contributors
|
4
|
-
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
4
|
of this software and associated documentation files (the "Software"), to deal
|
7
5
|
in the Software without restriction, including without limitation the rights
|