gromit 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/MIT-LICENSE +1 -1
 - data/README.md +34 -2
 - data/app/controllers/gromit/gromit_controller.rb +1 -0
 - data/app/helpers/gromit/application_helper.rb +1 -1
 - data/app/jobs/gromit/application_job.rb +1 -1
 - data/app/mailers/gromit/application_mailer.rb +1 -1
 - data/lib/gromit/markdown_parser.rb +2 -3
 - data/lib/gromit/uploader.rb +2 -1
 - data/lib/gromit/version.rb +1 -1
 - data/lib/gromit.rb +16 -14
 - 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: f81be5c3be11802b49cafcd1c3fe572acadd5cee48cb9fc71a74f631ab95b3d2
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 351fecf234d88f33670d78652b4caa28ff181ec9dae06a1ea0273b8759237606
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: eb0d33c49e7f3ece41f7e9fc59c3ca47eecdc4bf7113d9e50edd9353cbe0a278fd6a863b5fe2ca0ffdaf9c24cb91f8605336d4b1aae0c4001a43ab1cdbc82720
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 8e0bd27547c8230ae29fedb5bdb7c095d357044f1160f9ac4c2b27ae0dcedc5b1bd63357a206e6e7661b3bd5909b409bce08809481ae8fa266837711b0879f94
         
     | 
    
        data/MIT-LICENSE
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,8 +1,40 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Gromit
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
            Your documentation search assitant
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            ## Usage
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            Make sure to provide your OpenAI key in a `.env` file
         
     | 
| 
      
 7 
     | 
    
         
            +
            ```
         
     | 
| 
      
 8 
     | 
    
         
            +
            OPENAPI_ACCESS_TOKEN=your-openai-token
         
     | 
| 
      
 9 
     | 
    
         
            +
            ```
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            To mount the Gromit engine in Rails 7 add this line to your routes:
         
     | 
| 
      
 12 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 13 
     | 
    
         
            +
            Rails.application.routes.draw do
         
     | 
| 
      
 14 
     | 
    
         
            +
              mount Gromit::Engine => "/"
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
      
 16 
     | 
    
         
            +
            ```
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            Gromit provides the following routes:
         
     | 
| 
      
 19 
     | 
    
         
            +
            ```
         
     | 
| 
      
 20 
     | 
    
         
            +
            Routes for Gromit::Engine:
         
     | 
| 
      
 21 
     | 
    
         
            +
            healthcheck GET  /healthcheck(.:format) gromit/gromit#healthcheck {:format=>:json}
         
     | 
| 
      
 22 
     | 
    
         
            +
                 search POST /search(.:format)      gromit/gromit#search {:format=>:json}
         
     | 
| 
      
 23 
     | 
    
         
            +
                 upsert POST /upsert(.:format)      gromit/gromit#upsert {:format=>:json}
         
     | 
| 
      
 24 
     | 
    
         
            +
            ```
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            To index your documentation locally you can use `gromit-reindexer`. This will update `redis-stack-server` running on your machine.
         
     | 
| 
      
 27 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 28 
     | 
    
         
            +
            bundle exec gromit-reindexer -s /path/to/your/docs
         
     | 
| 
      
 29 
     | 
    
         
            +
            ```
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            To remotely upsert your documentation you can use `gromit-uploader`.
         
     | 
| 
      
 32 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 33 
     | 
    
         
            +
            BASE_URL=https://gromit-rails.example.com bundle exec gromit-uploader -s /path/to/your/docs
         
     | 
| 
      
 34 
     | 
    
         
            +
            ```
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            For a working example of a Rails 7 application using Gromit check out:
         
     | 
| 
      
 37 
     | 
    
         
            +
            https://github.com/releasehub-com/gromit-example
         
     | 
| 
       6 
38 
     | 
    
         | 
| 
       7 
39 
     | 
    
         
             
            ## Installation
         
     | 
| 
       8 
40 
     | 
    
         
             
            Add this line to your application's Gemfile:
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         | 
| 
       2 
2 
     | 
    
         
             
            class Gromit::MarkdownParser
         
     | 
| 
       3 
     | 
    
         
            -
              attr_reader :sections
         
     | 
| 
      
 3 
     | 
    
         
            +
              attr_reader :sections, :file_path
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
              class << self 
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
         @@ -58,7 +58,6 @@ class Gromit::MarkdownParser 
     | 
|
| 
       58 
58 
     | 
    
         
             
                  data = redis.get(section_id)
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
60 
     | 
    
         
             
                  if data.nil?
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
61 
     | 
    
         
             
                    # OpenAI recommends replacing newlines with spaces for best results (specific to embeddings)
         
     | 
| 
       63 
62 
     | 
    
         
             
                    input = section.gsub(/\n/m, ' ')
         
     | 
| 
       64 
63 
     | 
    
         
             
                    response = openai.embeddings(parameters: { input: input, model: "text-embedding-ada-002"})
         
     | 
| 
         @@ -121,7 +120,7 @@ class Gromit::MarkdownParser 
     | 
|
| 
       121 
120 
     | 
    
         | 
| 
       122 
121 
     | 
    
         
             
              def parse_file
         
     | 
| 
       123 
122 
     | 
    
         
             
                current_section = []
         
     | 
| 
       124 
     | 
    
         
            -
                File.read( 
     | 
| 
      
 123 
     | 
    
         
            +
                File.read(file_path).lines do |line|
         
     | 
| 
       125 
124 
     | 
    
         
             
                  # Check if the line is a header (starts with one or more '#' characters)
         
     | 
| 
       126 
125 
     | 
    
         
             
                  if header?(line)
         
     | 
| 
       127 
126 
     | 
    
         
             
                    # Save the previous section if it's not empty
         
     | 
    
        data/lib/gromit/uploader.rb
    CHANGED
    
    | 
         @@ -25,6 +25,7 @@ class Gromit::Uploader 
     | 
|
| 
       25 
25 
     | 
    
         
             
                  end.parse!
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                  path = Pathname.new(options.fetch(:source_dir, ''))
         
     | 
| 
      
 28 
     | 
    
         
            +
                  
         
     | 
| 
       28 
29 
     | 
    
         
             
                  unless path.exist?
         
     | 
| 
       29 
30 
     | 
    
         
             
                    puts "Error: The source directory (-s or --source) doesn't exist or is not specified."
         
     | 
| 
       30 
31 
     | 
    
         
             
                    exit 1
         
     | 
| 
         @@ -33,7 +34,7 @@ class Gromit::Uploader 
     | 
|
| 
       33 
34 
     | 
    
         
             
                  sections = Gromit::MarkdownParser.process(path.to_s)
         
     | 
| 
       34 
35 
     | 
    
         
             
                  sections.each do |section|
         
     | 
| 
       35 
36 
     | 
    
         
             
                    puts "uploading: #{section[:file]} section: #{section[:section_title]}"
         
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
      
 37 
     | 
    
         
            +
                    Partay.post('/upsert', { headers: {"Content-Type" => "application/json"}, body: section.to_json })
         
     | 
| 
       37 
38 
     | 
    
         
             
                  end
         
     | 
| 
       38 
39 
     | 
    
         
             
                end
         
     | 
| 
       39 
40 
     | 
    
         
             
              end
         
     | 
    
        data/lib/gromit/version.rb
    CHANGED
    
    
    
        data/lib/gromit.rb
    CHANGED
    
    | 
         @@ -4,6 +4,20 @@ require "gromit/engine" 
     | 
|
| 
       4 
4 
     | 
    
         
             
            module Gromit
         
     | 
| 
       5 
5 
     | 
    
         
             
              class Search
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
                EMBEDDINGS_SCHEMA = {
         
     | 
| 
      
 8 
     | 
    
         
            +
                  id: "TAG",
         
     | 
| 
      
 9 
     | 
    
         
            +
                  page_id: "TAG",
         
     | 
| 
      
 10 
     | 
    
         
            +
                  section_id: "TAG",
         
     | 
| 
      
 11 
     | 
    
         
            +
                  file: "TEXT",
         
     | 
| 
      
 12 
     | 
    
         
            +
                  title: "TEXT",
         
     | 
| 
      
 13 
     | 
    
         
            +
                  content: "TEXT",
         
     | 
| 
      
 14 
     | 
    
         
            +
                  checksum: "TEXT",
         
     | 
| 
      
 15 
     | 
    
         
            +
                  token_count: "NUMERIC",
         
     | 
| 
      
 16 
     | 
    
         
            +
                  embedding: "VECTOR FLAT 6 DIM 1536 DISTANCE_METRIC COSINE TYPE FLOAT64",
         
     | 
| 
      
 17 
     | 
    
         
            +
                }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                EMBEDDINGS_PREAMBLE = "FT.CREATE index ON JSON PREFIX 1 item: SCHEMA "
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       7 
21 
     | 
    
         
             
                def find_by_embedding(embedding)
         
     | 
| 
       8 
22 
     | 
    
         
             
                  results = redis.call([
         
     | 
| 
       9 
23 
     | 
    
         
             
                    "FT.SEARCH", "index", "@embedding:[VECTOR_RANGE $r $BLOB]=>{$YIELD_DISTANCE_AS: my_scores}",
         
     | 
| 
         @@ -29,24 +43,12 @@ module Gromit 
     | 
|
| 
       29 
43 
     | 
    
         
             
                end
         
     | 
| 
       30 
44 
     | 
    
         | 
| 
       31 
45 
     | 
    
         
             
                def create_index
         
     | 
| 
       32 
     | 
    
         
            -
                   
     | 
| 
       33 
     | 
    
         
            -
                    id: "TAG",
         
     | 
| 
       34 
     | 
    
         
            -
                    page_id: "TAG",
         
     | 
| 
       35 
     | 
    
         
            -
                    section_id: "TAG",
         
     | 
| 
       36 
     | 
    
         
            -
                    file: "TEXT",
         
     | 
| 
       37 
     | 
    
         
            -
                    title: "TEXT",
         
     | 
| 
       38 
     | 
    
         
            -
                    content: "TEXT",
         
     | 
| 
       39 
     | 
    
         
            -
                    checksum: "TEXT",
         
     | 
| 
       40 
     | 
    
         
            -
                    token_count: "NUMERIC",
         
     | 
| 
       41 
     | 
    
         
            -
                    embedding: "VECTOR FLAT 6 DIM 1536 DISTANCE_METRIC COSINE TYPE FLOAT64",
         
     | 
| 
       42 
     | 
    
         
            -
                  }
         
     | 
| 
       43 
     | 
    
         
            -
                  preamble = "FT.CREATE index ON JSON PREFIX 1 item: SCHEMA "
         
     | 
| 
       44 
     | 
    
         
            -
                  command = (preamble + schema.map{|name,type| "$.#{name} AS #{name} #{type}"}.join(" ")).split(" ")
         
     | 
| 
      
 46 
     | 
    
         
            +
                  command = (EMBEDDINGS_PREAMBLE + EMBEDDINGS_SCHEMA.map{|name,type| "$.#{name} AS #{name} #{type}"}.join(" ")).split(" ")
         
     | 
| 
       45 
47 
     | 
    
         
             
                  redis.call(command)
         
     | 
| 
       46 
48 
     | 
    
         
             
                end
         
     | 
| 
       47 
49 
     | 
    
         | 
| 
       48 
50 
     | 
    
         
             
                def redis
         
     | 
| 
       49 
     | 
    
         
            -
                  @redis ||=  
     | 
| 
      
 51 
     | 
    
         
            +
                  @redis ||= Gromit::MarkdownParser.redis
         
     | 
| 
       50 
52 
     | 
    
         
             
                end
         
     | 
| 
       51 
53 
     | 
    
         | 
| 
       52 
54 
     | 
    
         
             
              end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: gromit
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - David Giffin
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2023-05- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-05-08 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: dotenv
         
     |