activeagent 0.0.1.alpha → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +153 -0
- data/Rakefile +3 -0
- data/lib/active_agent/README.md +21 -0
- data/lib/active_agent/action_prompt/README.md +44 -0
- data/lib/active_agent/action_prompt/base.rb +0 -0
- data/lib/active_agent/action_prompt/collector.rb +34 -0
- data/lib/active_agent/action_prompt/message.rb +44 -0
- data/lib/active_agent/action_prompt/prompt.rb +79 -0
- data/lib/active_agent/action_prompt.rb +127 -0
- data/lib/active_agent/base.rb +439 -0
- data/lib/active_agent/callbacks.rb +31 -0
- data/lib/active_agent/deprecator.rb +7 -0
- data/lib/active_agent/engine.rb +14 -0
- data/lib/active_agent/generation.rb +78 -0
- data/lib/active_agent/generation_job.rb +47 -0
- data/lib/active_agent/generation_methods.rb +60 -0
- data/lib/active_agent/generation_provider/README.md +17 -0
- data/lib/active_agent/generation_provider/base.rb +36 -0
- data/lib/active_agent/generation_provider/open_ai_provider.rb +68 -0
- data/lib/active_agent/generation_provider/response.rb +15 -0
- data/lib/active_agent/generation_provider.rb +63 -0
- data/lib/active_agent/inline_preview_interceptor.rb +60 -0
- data/lib/active_agent/log_subscriber.rb +44 -0
- data/lib/active_agent/operation.rb +13 -0
- data/lib/active_agent/parameterized.rb +66 -0
- data/lib/active_agent/preview.rb +133 -0
- data/lib/active_agent/prompt_helper.rb +19 -0
- data/lib/active_agent/queued_generation.rb +12 -0
- data/lib/active_agent/railtie.rb +89 -0
- data/lib/active_agent/rescuable.rb +34 -0
- data/lib/active_agent/service.rb +25 -0
- data/lib/active_agent/test_case.rb +125 -0
- data/lib/active_agent/version.rb +3 -0
- data/lib/active_agent.rb +27 -5
- data/lib/generators/active_agent/USAGE +18 -0
- data/lib/generators/active_agent/agent_generator.rb +63 -0
- data/lib/generators/active_agent/templates/action.html.erb.tt +0 -0
- data/lib/generators/active_agent/templates/action.json.jbuilder.tt +14 -0
- data/lib/generators/active_agent/templates/agent.rb.tt +14 -0
- data/lib/generators/active_agent/templates/agent_spec.rb.tt +0 -0
- data/lib/generators/active_agent/templates/agent_test.rb.tt +0 -0
- data/lib/generators/active_agent/templates/application_agent.rb.tt +4 -0
- metadata +128 -3
@@ -0,0 +1,125 @@
|
|
1
|
+
# # frozen_string_literal: true
|
2
|
+
|
3
|
+
# require_relative "test_helper"
|
4
|
+
# require "active_support/test_case"
|
5
|
+
# require "rails-dom-testing"
|
6
|
+
|
7
|
+
# module ActiveAgent
|
8
|
+
# class NonInferrableAgentError < ::StandardError
|
9
|
+
# def initialize(name)
|
10
|
+
# super("Unable to determine the agent to test from #{name}. " \
|
11
|
+
# "You'll need to specify it using tests YourAgent in your " \
|
12
|
+
# "test case definition")
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
|
16
|
+
# class TestCase < ActiveSupport::TestCase
|
17
|
+
# module ClearTestDeliveries
|
18
|
+
# extend ActiveSupport::Concern
|
19
|
+
|
20
|
+
# included do
|
21
|
+
# setup :clear_test_generations
|
22
|
+
# teardown :clear_test_generations
|
23
|
+
# end
|
24
|
+
|
25
|
+
# private
|
26
|
+
|
27
|
+
# def clear_test_generations
|
28
|
+
# if ActiveAgent::Base.generation_method == :test
|
29
|
+
# ActiveAgent::Base.generations.clear
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
|
34
|
+
# module Behavior
|
35
|
+
# extend ActiveSupport::Concern
|
36
|
+
|
37
|
+
# include ActiveSupport::Testing::ConstantLookup
|
38
|
+
# include TestHelper
|
39
|
+
# include Rails::Dom::Testing::Assertions::SelectorAssertions
|
40
|
+
# include Rails::Dom::Testing::Assertions::DomAssertions
|
41
|
+
|
42
|
+
# included do
|
43
|
+
# class_attribute :_agent_class
|
44
|
+
# setup :initialize_test_generations
|
45
|
+
# setup :set_expected_prompt
|
46
|
+
# teardown :restore_test_generations
|
47
|
+
# ActiveSupport.run_load_hooks(:active_agent_test_case, self)
|
48
|
+
# end
|
49
|
+
|
50
|
+
# module ClassMethods
|
51
|
+
# def tests(agent)
|
52
|
+
# case agent
|
53
|
+
# when String, Symbol
|
54
|
+
# self._agent_class = agent.to_s.camelize.constantize
|
55
|
+
# when Module
|
56
|
+
# self._agent_class = agent
|
57
|
+
# else
|
58
|
+
# raise NonInferrableAgentError.new(agent)
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
|
62
|
+
# def agent_class
|
63
|
+
# if agent = _agent_class
|
64
|
+
# agent
|
65
|
+
# else
|
66
|
+
# tests determine_default_agent(name)
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
|
70
|
+
# def determine_default_agent(name)
|
71
|
+
# agent = determine_constant_from_test_name(name) do |constant|
|
72
|
+
# Class === constant && constant < ActiveAgent::Base
|
73
|
+
# end
|
74
|
+
# raise NonInferrableAgentError.new(name) if agent.nil?
|
75
|
+
# agent
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
|
79
|
+
# # Reads the fixture file for the given agent.
|
80
|
+
# #
|
81
|
+
# # This is useful when testing agents by being able to write the body of
|
82
|
+
# # an promt inside a fixture. See the testing guide for a concrete example:
|
83
|
+
# # https://guides.rubyonrails.org/testing.html#revenge-of-the-fixtures
|
84
|
+
# def read_fixture(action)
|
85
|
+
# IO.readlines(File.join(Rails.root, "test", "fixtures", self.class.agent_class.name.underscore, action))
|
86
|
+
# end
|
87
|
+
|
88
|
+
# private
|
89
|
+
|
90
|
+
# def initialize_test_generations
|
91
|
+
# set_generation_method :test
|
92
|
+
# @old_perform_generations = ActiveAgent::Base.perform_generations
|
93
|
+
# ActiveAgent::Base.perform_generations = true
|
94
|
+
# ActiveAgent::Base.generations.clear
|
95
|
+
# end
|
96
|
+
|
97
|
+
# def restore_test_generations
|
98
|
+
# restore_generation_method
|
99
|
+
# ActiveAgent::Base.perform_generations = @old_perform_generations
|
100
|
+
# end
|
101
|
+
|
102
|
+
# def set_generation_method(method)
|
103
|
+
# @old_generation_method = ActiveAgent::Base.generation_method
|
104
|
+
# ActiveAgent::Base.generation_method = method
|
105
|
+
# end
|
106
|
+
|
107
|
+
# def restore_generation_method
|
108
|
+
# ActiveAgent::Base.generations.clear
|
109
|
+
# ActiveAgent::Base.generation_method = @old_generation_method
|
110
|
+
# end
|
111
|
+
|
112
|
+
# def set_expected_prompt
|
113
|
+
# @expected = ActiveAgent::ActionPrompt::Prompt.new
|
114
|
+
# @expected.content_type ["text", "plain", {"charset" => charset}]
|
115
|
+
# @expected.mime_version = "1.0"
|
116
|
+
# end
|
117
|
+
|
118
|
+
# def charset
|
119
|
+
# "UTF-8"
|
120
|
+
# end
|
121
|
+
# end
|
122
|
+
|
123
|
+
# include Behavior
|
124
|
+
# end
|
125
|
+
# end
|
data/lib/active_agent.rb
CHANGED
@@ -1,25 +1,47 @@
|
|
1
|
-
# lib/active_agent.rb
|
2
1
|
require "yaml"
|
2
|
+
require "abstract_controller"
|
3
3
|
require "active_agent/version"
|
4
4
|
require "active_agent/deprecator"
|
5
|
-
require "active_agent/
|
5
|
+
require "active_agent/railtie" if defined?(Rails)
|
6
|
+
|
6
7
|
require "active_support"
|
8
|
+
require "active_support/rails"
|
9
|
+
require "active_support/core_ext/class"
|
10
|
+
require "active_support/core_ext/module/attr_internal"
|
11
|
+
require "active_support/core_ext/string/inflections"
|
12
|
+
require "active_support/lazy_load_hooks"
|
7
13
|
|
8
14
|
module ActiveAgent
|
9
15
|
extend ActiveSupport::Autoload
|
10
16
|
|
17
|
+
eager_autoload do
|
18
|
+
autoload :Collector
|
19
|
+
end
|
20
|
+
|
11
21
|
autoload :Base
|
12
22
|
autoload :Callbacks
|
13
|
-
autoload :
|
14
|
-
autoload :
|
23
|
+
autoload :InlinePreviewInterceptor
|
24
|
+
autoload :PromptHelper
|
15
25
|
autoload :Generation
|
26
|
+
autoload :GenerationMethods
|
16
27
|
autoload :GenerationProvider
|
17
|
-
autoload :GenerationJob
|
18
28
|
autoload :QueuedGeneration
|
29
|
+
autoload :Parameterized
|
30
|
+
autoload :Preview
|
31
|
+
autoload :Previews, "active_agent/preview"
|
32
|
+
autoload :GenerationJob
|
19
33
|
|
20
34
|
class << self
|
21
35
|
attr_accessor :config
|
22
36
|
|
37
|
+
def eager_load!
|
38
|
+
super
|
39
|
+
|
40
|
+
Base.descendants.each do |agent|
|
41
|
+
agent.eager_load! unless agent.abstract?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
23
45
|
def configure
|
24
46
|
yield self
|
25
47
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Description:
|
2
|
+
Generates a new agent and its views. Passes the agent name, either
|
3
|
+
CamelCased or under_scored, and an optional list of prompts as arguments.
|
4
|
+
|
5
|
+
This generates a agent class in app/agents and invokes your template
|
6
|
+
engine and test framework generators.
|
7
|
+
|
8
|
+
Examples:
|
9
|
+
`bin/rails generate agent inventory search`
|
10
|
+
|
11
|
+
creates a sign up mailer class, views, and test:
|
12
|
+
Agent: app/agents/inventory_agent.rb
|
13
|
+
Views: app/views/inventory_agent/search.text.erb [...]
|
14
|
+
Test: test/agents/inventory_agent_test.rb
|
15
|
+
|
16
|
+
`bin/rails generate agent inventory search update report`
|
17
|
+
|
18
|
+
creates an inventory agent with search, update, and report actions.
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveAgent
|
4
|
+
module Generators
|
5
|
+
class AgentGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
|
8
|
+
argument :actions, type: :array, default: [], banner: "method method"
|
9
|
+
|
10
|
+
check_class_collision suffix: "Agent"
|
11
|
+
|
12
|
+
def create_agent_file
|
13
|
+
template "agent.rb", File.join("app/agents", class_path, "#{file_name}_agent.rb")
|
14
|
+
|
15
|
+
in_root do
|
16
|
+
if behavior == :invoke && !File.exist?(application_agent_file_name)
|
17
|
+
template "application_agent.rb", application_agent_file_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_test_file
|
23
|
+
if test_framework == :rspec
|
24
|
+
template "agent_spec.rb", File.join("spec/agents", class_path, "#{file_name}_agent_spec.rb")
|
25
|
+
else
|
26
|
+
template "agent_test.rb", File.join("test/agents", class_path, "#{file_name}_agent_test.rb")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_view_files
|
31
|
+
actions.each do |action|
|
32
|
+
@action = action
|
33
|
+
@schema_path = File.join("app/views", class_path, file_name, "#{action}.json.jbuilder")
|
34
|
+
@view_path = File.join("app/views", class_path, file_name, "#{action}.html.#{template_engine}")
|
35
|
+
template "action.json.jbuilder", @schema_path
|
36
|
+
template "action.html.#{template_engine}", @view_path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
private
|
42
|
+
def test_framework
|
43
|
+
::Rails.application.config.generators.options[:rails][:test_framework]
|
44
|
+
end
|
45
|
+
|
46
|
+
def template_engine
|
47
|
+
::Rails.application.config.generators.options[:rails][:template_engine]
|
48
|
+
end
|
49
|
+
|
50
|
+
def file_name # :doc:
|
51
|
+
@_file_name ||= super + "_agent"
|
52
|
+
end
|
53
|
+
|
54
|
+
def application_agent_file_name
|
55
|
+
@_application_agent_file_name ||= if mountable_engine?
|
56
|
+
"app/agents/#{namespaced_path}/application_agent.rb"
|
57
|
+
else
|
58
|
+
"app/agents/application_agent.rb"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
json.type :function
|
2
|
+
json.function do
|
3
|
+
json.name action_name
|
4
|
+
json.description "TODO: Write a description for this action"
|
5
|
+
json.parameters do
|
6
|
+
json.type :object
|
7
|
+
json.properties do
|
8
|
+
json.param_name do
|
9
|
+
json.type :string
|
10
|
+
json.description "The param_description"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= class_name %>Agent < ApplicationAgent
|
3
|
+
<% actions.each_with_index do |action, index| -%>
|
4
|
+
<% if index != 0 -%>
|
5
|
+
|
6
|
+
<% end -%>
|
7
|
+
def <%= action %>
|
8
|
+
@message = "Cats go.."
|
9
|
+
|
10
|
+
prompt message: @message
|
11
|
+
end
|
12
|
+
<% end -%>
|
13
|
+
end
|
14
|
+
<% end -%>
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,15 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeagent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Bowen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
12
|
-
dependencies:
|
11
|
+
date: 2024-11-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionview
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '7.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '7.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '7.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activemodel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '7.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '7.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activejob
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '7.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '7.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '7.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '7.2'
|
13
97
|
description: A simple way to perform long running LLM background jobs and streaming
|
14
98
|
responses
|
15
99
|
email: jusbowen@gmail.com
|
@@ -17,7 +101,48 @@ executables: []
|
|
17
101
|
extensions: []
|
18
102
|
extra_rdoc_files: []
|
19
103
|
files:
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
20
106
|
- lib/active_agent.rb
|
107
|
+
- lib/active_agent/README.md
|
108
|
+
- lib/active_agent/action_prompt.rb
|
109
|
+
- lib/active_agent/action_prompt/README.md
|
110
|
+
- lib/active_agent/action_prompt/base.rb
|
111
|
+
- lib/active_agent/action_prompt/collector.rb
|
112
|
+
- lib/active_agent/action_prompt/message.rb
|
113
|
+
- lib/active_agent/action_prompt/prompt.rb
|
114
|
+
- lib/active_agent/base.rb
|
115
|
+
- lib/active_agent/callbacks.rb
|
116
|
+
- lib/active_agent/deprecator.rb
|
117
|
+
- lib/active_agent/engine.rb
|
118
|
+
- lib/active_agent/generation.rb
|
119
|
+
- lib/active_agent/generation_job.rb
|
120
|
+
- lib/active_agent/generation_methods.rb
|
121
|
+
- lib/active_agent/generation_provider.rb
|
122
|
+
- lib/active_agent/generation_provider/README.md
|
123
|
+
- lib/active_agent/generation_provider/base.rb
|
124
|
+
- lib/active_agent/generation_provider/open_ai_provider.rb
|
125
|
+
- lib/active_agent/generation_provider/response.rb
|
126
|
+
- lib/active_agent/inline_preview_interceptor.rb
|
127
|
+
- lib/active_agent/log_subscriber.rb
|
128
|
+
- lib/active_agent/operation.rb
|
129
|
+
- lib/active_agent/parameterized.rb
|
130
|
+
- lib/active_agent/preview.rb
|
131
|
+
- lib/active_agent/prompt_helper.rb
|
132
|
+
- lib/active_agent/queued_generation.rb
|
133
|
+
- lib/active_agent/railtie.rb
|
134
|
+
- lib/active_agent/rescuable.rb
|
135
|
+
- lib/active_agent/service.rb
|
136
|
+
- lib/active_agent/test_case.rb
|
137
|
+
- lib/active_agent/version.rb
|
138
|
+
- lib/generators/active_agent/USAGE
|
139
|
+
- lib/generators/active_agent/agent_generator.rb
|
140
|
+
- lib/generators/active_agent/templates/action.html.erb.tt
|
141
|
+
- lib/generators/active_agent/templates/action.json.jbuilder.tt
|
142
|
+
- lib/generators/active_agent/templates/agent.rb.tt
|
143
|
+
- lib/generators/active_agent/templates/agent_spec.rb.tt
|
144
|
+
- lib/generators/active_agent/templates/agent_test.rb.tt
|
145
|
+
- lib/generators/active_agent/templates/application_agent.rb.tt
|
21
146
|
homepage: https://rubygems.org/gems/activeagent
|
22
147
|
licenses:
|
23
148
|
- MIT
|