activeai 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/activeai/behavior/llm/write_function_call.rb +16 -11
- data/lib/activeai/controller.rb +5 -1
- data/lib/activeai/router.rb +15 -8
- data/lib/activeai/version.rb +1 -1
- data/lib/activeai.rb +6 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 675b7c115dce4bd1abf7218ab295c22d529bf7437d5fd30cfaa00038725df583
|
4
|
+
data.tar.gz: ff3c7267829708f773181dbd4774b7a1ed5a1ffd92bb4f7fa60487d16055efe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b703e871c0194a603707d7b163cd5a914c7ba3de9d90eabf1301385481acc65445c4a3129232469a745fef63cb21280c96782caf5719e0dd03c3568eac44c68d
|
7
|
+
data.tar.gz: 74f0c382efe4c2b20dc9d9f2c9ad4aa38ec11af314f9aa6b25a770b9c40ad57387d4016f02465072441be426a769dc07b3630830db70418a18a80faeca753d99
|
data/README.md
CHANGED
@@ -108,7 +108,7 @@ controller.call("Pay Mom R127 for groceries")
|
|
108
108
|
It's possible to instantiate an `ActiveAI::Router`, load up the examples from multiple controllers, and then have it handle many types of requests. It does this in a similar way to how the controller uses an LLM to map to action and params, but it concatenates all controller routing examples and strips out the parameter preparation step for efficiency, since the controller handles this.
|
109
109
|
|
110
110
|
```ruby
|
111
|
-
router = ActiveAI::Router.new
|
111
|
+
router = ActiveAI::Router.new # TODO you need to add providers now.. should be optional?
|
112
112
|
|
113
113
|
# load all auto-detected routes:
|
114
114
|
router.auto_load_routing(Rails.root.join('config','routes')) # loads all .yml files as controller examples
|
@@ -6,26 +6,31 @@ class ActiveAI::Behavior::LLM::WriteFunctionCall < ActiveAI::Behavior::LLM
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def base_prompt
|
9
|
-
@state[:examples].map do |example|
|
10
|
-
[
|
11
|
-
|
12
|
-
example[:code]
|
13
|
-
].join("\n")
|
14
|
-
end.join("\n\n") + "\n\n"
|
9
|
+
(@state[:examples].map do |example|
|
10
|
+
"/* #{example[:description]} */\n#{example[:code]}"
|
11
|
+
end + [""]).join("<|endoftext|>")
|
15
12
|
end
|
16
13
|
|
17
14
|
def call(comment)
|
18
|
-
prompt = base_prompt
|
19
|
-
prompt += "
|
20
|
-
complete_result = complete(prompt, stop: "\n")
|
15
|
+
prompt = base_prompt
|
16
|
+
prompt += "/* #{comment} */\n"
|
21
17
|
|
22
|
-
#
|
18
|
+
complete_result = complete(prompt) # this still breaks sometimes by generating like 50 functions instead of stopping. think i fixed it? forgot an <|endoftext|> at the end
|
19
|
+
|
20
|
+
# puts prompt
|
21
|
+
# puts complete_result
|
23
22
|
|
24
23
|
completion = complete_result['choices'][0]['text']
|
24
|
+
completion = completion.strip.gsub("\n", "\\n") # fixes parsing errors (in JSON??)
|
25
25
|
|
26
|
-
matcher = /(
|
26
|
+
matcher = /(.*?)\((.*)\)/m # should be made ungreedy, but then i dont see when it over-completes because it fails silently
|
27
27
|
matches = matcher.match(completion)
|
28
28
|
|
29
|
+
if matches.nil?
|
30
|
+
# binding.pry
|
31
|
+
raise "Unmatched router response in #{self.class}"
|
32
|
+
end
|
33
|
+
|
29
34
|
return {
|
30
35
|
text: completion.strip,
|
31
36
|
path: matches[1],
|
data/lib/activeai/controller.rb
CHANGED
@@ -9,7 +9,7 @@ class ActiveAI::Controller
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.load_routing(routes_config)
|
12
|
-
@llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-
|
12
|
+
@llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-cushman-001', temperature: 0)
|
13
13
|
|
14
14
|
examples = ActiveAI.route_examples_to_function_call_examples(routes_config['examples'])
|
15
15
|
self.routing_behavior = ActiveAI::Behavior::LLM::WriteFunctionCall.new(@llm, { examples: examples })
|
@@ -17,6 +17,10 @@ class ActiveAI::Controller
|
|
17
17
|
|
18
18
|
attr_accessor :params
|
19
19
|
|
20
|
+
def initialize(provider)
|
21
|
+
@provider = provider
|
22
|
+
end
|
23
|
+
|
20
24
|
def prepare_action(request)
|
21
25
|
# samples to parse:
|
22
26
|
# plugins.slack.send_message({ \"channel\": \"#general\", \"text\": \"Hi\" })
|
data/lib/activeai/router.rb
CHANGED
@@ -4,7 +4,7 @@ class ActiveAI::Router
|
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@routings = []
|
7
|
-
@llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-
|
7
|
+
@llm = ActiveAI::NeuralNetwork::GPT3.new(ActiveAI.config[:gpt3_token], model: 'code-cushman-001', temperature: 0)
|
8
8
|
end
|
9
9
|
|
10
10
|
def add_controller_routing(routing)
|
@@ -69,11 +69,18 @@ class ActiveAI::Router
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
# This stopped being necessary, because we find controller and call it elsewhere:
|
73
|
+
# def call(request, providers=nil)
|
74
|
+
# if controller = find_controller(request)
|
75
|
+
|
76
|
+
# provider = if providers.respond_to?(:find_by)
|
77
|
+
# provider_name = controller.to_s.gsub("Plugins::", "").gsub("Controller","")
|
78
|
+
# providers.find_by(name: provider_name)
|
79
|
+
# end
|
80
|
+
|
81
|
+
# controller.new(provider).call(request)
|
82
|
+
# else
|
83
|
+
# return nil
|
84
|
+
# end
|
85
|
+
# end
|
79
86
|
end
|
data/lib/activeai/version.rb
CHANGED
data/lib/activeai.rb
CHANGED
@@ -1,12 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "activeai/behavior"
|
4
|
-
require_relative "activeai/configuration"
|
5
|
-
require_relative "activeai/controller"
|
6
|
-
require_relative "activeai/neural_network"
|
7
|
-
require_relative "activeai/router"
|
8
|
-
require_relative "activeai/version"
|
9
|
-
|
10
3
|
module ActiveAI
|
11
4
|
class Error < StandardError; end
|
12
5
|
|
@@ -30,3 +23,9 @@ module ActiveAI
|
|
30
23
|
|
31
24
|
end
|
32
25
|
|
26
|
+
require_relative "activeai/behavior"
|
27
|
+
require_relative "activeai/configuration"
|
28
|
+
require_relative "activeai/controller"
|
29
|
+
require_relative "activeai/neural_network"
|
30
|
+
require_relative "activeai/router"
|
31
|
+
require_relative "activeai/version"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeriko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|