Skip to content

Commit

Permalink
cop
Browse files Browse the repository at this point in the history
  • Loading branch information
sebyx07 committed Aug 3, 2024
1 parent c5a7047 commit 4ebf592
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions lib/ai_agent/embeddings/indexers/basic_fs_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -60,6 +68,14 @@ def files
end
end
end

def start_watching
@watching = true
end

def stop_watching
@watching = false
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/ai_agent/tools/base_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions lib/ai_agent/tools/knowledge/query_embeddings.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4ebf592

Please sign in to comment.