diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cc55668..8346810 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,4 +24,6 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Run the default task - run: bundle exec rake + run: | + bundle exec rake + rubocop --parallel diff --git a/Gemfile b/Gemfile index 368748a..3ea70a4 100644 --- a/Gemfile +++ b/Gemfile @@ -18,3 +18,5 @@ gem 'vcr', '~> 6.2' gem 'webmock', '~> 3.23', '>= 3.23.1' gem 'lefthook', '~> 1.7', '>= 1.7.4' + +gem 'rspec-benchmark', '~> 0.6.0' diff --git a/Gemfile.lock b/Gemfile.lock index dc1676f..578f996 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,9 @@ GEM public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) base64 (0.2.0) + benchmark-malloc (0.2.0) + benchmark-perf (0.6.0) + benchmark-trend (0.4.0) bigdecimal (3.1.8) coderay (1.1.3) colorize (1.1.0) @@ -93,6 +96,11 @@ GEM rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) + rspec-benchmark (0.6.0) + benchmark-malloc (~> 0.2) + benchmark-perf (~> 0.6) + benchmark-trend (~> 0.4) + rspec (>= 3.0) rspec-core (3.13.0) rspec-support (~> 3.13.0) rspec-expectations (3.13.1) @@ -178,6 +186,7 @@ DEPENDENCIES pry (~> 0.14.2) rake (~> 13.0) rspec (~> 3.0) + rspec-benchmark (~> 0.6.0) rubocop-rails_config (~> 1.16) vcr (~> 6.2) webmock (~> 3.23, >= 3.23.1) diff --git a/README.md b/README.md index cc920ea..6cebbd6 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,9 @@ class MyTerminalChatAgent < AiAgent::Agents::TerminalBasicChatAgent end def indexer - @indexer ||= AiAgent::Embeddings::Indexers::BasicFsIndexer.new(configuration, embeddings_database) + @indexer ||= AiAgent::Embeddings::Indexers::BasicFsIndexer.new(configuration, embeddings_database).tap do |indexer| + indexer.update_indexes_for_new_changes = true + end end end agent = MyTerminalChatAgent.new diff --git a/lib/ai_agent/embeddings/indexers/basic_fs_indexer.rb b/lib/ai_agent/embeddings/indexers/basic_fs_indexer.rb index a68f638..7f92649 100644 --- a/lib/ai_agent/embeddings/indexers/basic_fs_indexer.rb +++ b/lib/ai_agent/embeddings/indexers/basic_fs_indexer.rb @@ -39,6 +39,14 @@ def ask(prompt, top_k = @configuration.embeddings_similar_limit) end end + def update_indexes_for_new_changes=(value) + if value + start_watching + else + stop_watching + end + end + private def files files = Dir.glob('**/*').map do |f| @@ -60,6 +68,14 @@ def files end end end + + def start_watching + @watching = true + end + + def stop_watching + @watching = false + end end end end diff --git a/lib/ai_agent/tools/base_tool.rb b/lib/ai_agent/tools/base_tool.rb index 946831d..2313d5b 100644 --- a/lib/ai_agent/tools/base_tool.rb +++ b/lib/ai_agent/tools/base_tool.rb @@ -9,6 +9,14 @@ def initialize(agent) @agent = agent @configuration = agent.configuration end + + def tool_definition + raise NotImplementedError + end + + def self.who_am_i_description + raise NotImplementedError + end end end end diff --git a/lib/ai_agent/tools/knowledge/query_embeddings.rb b/lib/ai_agent/tools/knowledge/query_embeddings.rb new file mode 100644 index 0000000..4673a56 --- /dev/null +++ b/lib/ai_agent/tools/knowledge/query_embeddings.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module AiAgent + module Tools + module Knowledge + class QueryEmbeddings < AiAgent::Tools::BaseTool + def tool_definition + @tool_definition ||= { + query_embeddings: { + execute: ->(params) do + query = params['query'] + AiAgent::Conversation::Message.new(:tool, query_embeddings(query)) + end, + description: 'Query the knowledge base for this current project. Use this tool to learn more about the project.', + parameters: { + type: 'object', + properties: { + query: { + type: 'string', + description: 'The query to execute.' + } + }, + required: ['query'] + }, + } + } + end + + def query_embeddings(query) + @agent.indexer.ask(query) + end + end + end + end +end