gromit 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b411bb60710e098511fe9815258c32df7bcc9f91faa8a18038602a1c8752bea
4
- data.tar.gz: 1bffad9cbc51e40c3224c760821b9d5db0f1588a97ed42d2e8475b35d958a64e
3
+ metadata.gz: 4c08834b2d4ab44b913db4ab7d38b09570afe1e379fe52c1cd0c373509b5bfd4
4
+ data.tar.gz: 603cbadb8f17fe8dea16ab04404f0f1fd619f0e13f1c400d66b1292906667b69
5
5
  SHA512:
6
- metadata.gz: b31fd9aad171338ae5d4b668c8d713e139af4ba26851f2867ae543c9ff9bda570a3b7bc9e02624e815b69765d02e7fab2d74771a7aa5a9d3087969488b9858ef
7
- data.tar.gz: ae864f780e131dc4f491119d0702da1f872d44d0d74c5bf17203cb0085580bbd352cd559884e5ddde90025b60e8b5e74724fe9c6fa1497fdfdd3280bdda8103f
6
+ metadata.gz: 503038957680864be947e60e00e2194f13fec7f4a6f64f40084d0adf4cc5fde72fd3016d23dfeb465a703bc870d4c1c952b5c3c8bf827f1bed5b1fffb3d29e06
7
+ data.tar.gz: 3fe22ab62a45597fc02cf9111deee1a23b29ecf906fd75c0c6026c1c51086bc70ab58f08af3de6605f505ddb7b1dd835ce2390990e6c61c98f49cf34c697ef0f
data/README.md CHANGED
@@ -1,14 +1,19 @@
1
1
  # Gromit
2
+
2
3
  Your documentation search assitant
3
4
 
4
5
  ## Usage
5
6
 
6
- Make sure to provide your OpenAI key in a `.env` file
7
- ```
8
- OPENAPI_ACCESS_TOKEN=your-openai-token
7
+ Make sure to provide your OpenAI token using the `OPENAPI_ACCESS_TOKEN` environment variable.
8
+
9
+ To mount the Gromit engine in Rails 7, require the engine from your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem "gromit", require: "gromit/engine"
9
13
  ```
10
14
 
11
- To mount the Gromit engine in Rails 7 add this line to your routes:
15
+ And add this line to your routes:
16
+
12
17
  ```ruby
13
18
  Rails.application.routes.draw do
14
19
  mount Gromit::Engine => "/"
@@ -16,6 +21,7 @@ end
16
21
  ```
17
22
 
18
23
  Gromit provides the following routes:
24
+
19
25
  ```
20
26
  Routes for Gromit::Engine:
21
27
  healthcheck GET /healthcheck(.:format) gromit/gromit#healthcheck {:format=>:json}
@@ -24,11 +30,13 @@ healthcheck GET /healthcheck(.:format) gromit/gromit#healthcheck {:format=>:jso
24
30
  ```
25
31
 
26
32
  To index your documentation locally you can use `gromit-reindexer`. This will update `redis-stack-server` running on your machine.
33
+
27
34
  ```bash
28
35
  bundle exec gromit-reindexer -s /path/to/your/docs
29
36
  ```
30
37
 
31
38
  To remotely upsert your documentation you can use `gromit-uploader`.
39
+
32
40
  ```bash
33
41
  BASE_URL=https://gromit-rails.example.com bundle exec gromit-uploader -s /path/to/your/docs
34
42
  ```
@@ -37,6 +45,7 @@ For a working example of a Rails 7 application using Gromit check out:
37
45
  https://github.com/releasehub-com/gromit-example
38
46
 
39
47
  ## Installation
48
+
40
49
  Add this line to your application's Gemfile:
41
50
 
42
51
  ```ruby
@@ -44,17 +53,24 @@ gem "gromit"
44
53
  ```
45
54
 
46
55
  And then execute:
56
+
47
57
  ```bash
48
58
  $ bundle
49
59
  ```
50
60
 
51
61
  Or install it yourself as:
62
+
52
63
  ```bash
53
64
  $ gem install gromit
54
65
  ```
55
66
 
56
67
  ## Contributing
68
+
57
69
  Contribution directions go here.
58
70
 
59
71
  ## License
72
+
60
73
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
+
75
+ ---
76
+ Made with love by the folks @ [release.com](https://release.com)
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/setup"
2
2
 
3
- APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
3
+ APP_RAKEFILE = File.expand_path("spec/fixtures/dummy/Rakefile", __dir__)
4
4
  load "rails/tasks/engine.rake"
5
5
 
6
6
  load "rails/tasks/statistics.rake"
@@ -2,6 +2,8 @@ require 'rejson'
2
2
 
3
3
  module Gromit
4
4
  class GromitController < ApplicationController
5
+ IM_A_TEAPOT = 418
6
+
5
7
  skip_before_action :verify_authenticity_token
6
8
 
7
9
  def healthcheck
@@ -16,14 +18,19 @@ module Gromit
16
18
 
17
19
  # create the index if it's not already there
18
20
  gromit.create_index
21
+ render json: { status: 'healthy', message: 'Redis connection is healthy' }
19
22
  else
20
- render json: { status: 'unhealthy', message: 'Redis connection is unhealthy' }
23
+ render json: { status: 'unhealthy', message: 'Redis connection is unhealthy' }, status: IM_A_TEAPOT
21
24
  end
22
25
  rescue Redis::CommandError, Redis::CannotConnectError => e
23
- if e.message == "Index already exists"
24
- render json: { status: 'healthy', message: 'Redis connection is healthy' }
26
+ if e.is_a?(Redis::CommandError)
27
+ if e.message == "Index already exists"
28
+ render json: { status: 'healthy', message: 'Redis connection is healthy' }
29
+ else
30
+ render json: { status: 'unhealthy', message: "Unknown command error" }, status: IM_A_TEAPOT
31
+ end
25
32
  else
26
- render json: { status: 'unhealthy', message: "Redis connection error: #{e.message}" }
33
+ render json: { status: 'unhealthy', message: "Redis connection error: #{e.message}" }, status: IM_A_TEAPOT
27
34
  end
28
35
  end
29
36
  end
@@ -31,7 +38,7 @@ module Gromit
31
38
  def search
32
39
  gromit = Gromit::Search.new
33
40
  result = gromit.find_by_embedding(params[:embedding])
34
- render json: { error: "", data: result }
41
+ render json: { data: result }
35
42
  end
36
43
 
37
44
  def upsert
@@ -43,8 +50,10 @@ module Gromit
43
50
  # Extract the key and value from the request data
44
51
  id = params[:id]
45
52
 
53
+ data = params.to_unsafe_h.deep_stringify_keys
54
+
46
55
  # Upsert the record into the Redis database
47
- gromit.redis.json_set("item:#{id}", Rejson::Path.root_path, params.to_unsafe_h.deep_stringify_keys)
56
+ gromit.redis.json_set("item:#{id}", Rejson::Path.root_path.str_path, data.except("action", "controller"))
48
57
 
49
58
  # Return a success response
50
59
  render json: { status: 'success', message: "Record upserted successfully", key: "item:#{id}" }
data/lib/gromit/engine.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "gromit"
1
2
  require "rails"
2
3
 
3
4
  module Gromit
@@ -1,8 +1,9 @@
1
+ require 'active_support/inflector/methods'
1
2
 
2
3
  class Gromit::MarkdownParser
3
4
  attr_reader :sections, :file_path
4
5
 
5
- class << self
6
+ class << self
6
7
 
7
8
  def redis
8
9
  @@redis ||= Redis.new(host: ENV.fetch("REDIS_HOST") { "127.0.0.1" }, port: ENV.fetch("REDIS_PORT") { "6379" }.to_i)
@@ -89,14 +90,14 @@ class Gromit::MarkdownParser
89
90
 
90
91
  # remove the .md extension from the end of the URLs from gitbook
91
92
  file.gsub!(/(\[[^\]]+?\])\((.*?)\.md([#a-z0-9]*)\)/) do |match|
92
- "#{$1}(#{$2}#{$3})"
93
+ "#{$1}(#{$2}#{$3})"
93
94
  end
94
95
 
95
- # handle "mentions"
96
+ # handle "mentions"
96
97
  file.gsub!(/\[([^\]]+?).md\]\((.*?)\.md([#a-z0-9]*) "mention"\)/) do |match|
97
98
  link = "#{$2}#{$3}"
98
- title = $1.gsub("-", ' ').titleize
99
- "[#{title}](#{link})"
99
+ title = ActiveSupport::Inflector.titleize($1.gsub("-", ' '))
100
+ "[#{title}](#{link})"
100
101
  end
101
102
 
102
103
  # convert gitbook hints to admonitions
@@ -1,16 +1,10 @@
1
1
  require 'bundler/setup'
2
2
  require 'openai'
3
- require 'dotenv'
4
3
  require 'optparse'
5
4
  require 'redis'
6
5
  require 'rejson'
7
- require 'active_support/all'
8
-
9
6
  require_relative 'markdown_parser'
10
7
 
11
- Dotenv.load
12
-
13
-
14
8
  class Gromit::Reindexer
15
9
  attr_accessor :redis
16
10
 
@@ -24,7 +18,7 @@ class Gromit::Reindexer
24
18
  options[:source_dir] = source_dir
25
19
  end
26
20
 
27
- opts.on('-d', '--drop', 'Drop and create index before reindexing') do
21
+ opts.on('-d', '--drop', 'Drop and create index before reindexing') do
28
22
  options[:drop] = true
29
23
  end
30
24
 
@@ -38,14 +32,14 @@ class Gromit::Reindexer
38
32
 
39
33
  # Instantiate the ToMkDocs class and perform the conversion
40
34
  reindexer = Gromit::Reindexer.new
41
- reindexer.run(options[:source_dir], drop: options[:drop])
35
+ reindexer.run(options[:source_dir], drop: options[:drop])
42
36
 
43
37
  puts "Reindexer completed successfully."
44
38
  end
45
39
  end
46
40
 
47
41
  def initialize
48
- @redis ||= Redis.new(host: ENV.fetch("REDIS_HOST") { "127.0.0.1" }, port: ENV.fetch("REDIS_PORT") { "6379" }.to_i)
42
+ @redis ||= Gromit::MarkdownParser.redis
49
43
  end
50
44
 
51
45
  def run(directory = nil, drop: false)
@@ -55,11 +49,12 @@ class Gromit::Reindexer
55
49
  gromit.recreate_index
56
50
  end
57
51
 
52
+ #TODO do we really want david's examples as the default here?
58
53
  directory ||= ENV.fetch("DOCS_DIRECTORY") { "/Users/david/development/docs/examples" }
59
54
  sections = Gromit::MarkdownParser.process(directory)
60
55
  sections.each do |section|
61
56
  puts "indexing: #{section[:file]} section: #{section[:section_title]}"
62
- data = section.stringify_keys
57
+ data = section.transform_keys(&:to_s)
63
58
  id = data['id']
64
59
  gromit.redis.json_set("item:#{id}", Rejson::Path.root_path, data)
65
60
  end
@@ -1,15 +1,11 @@
1
1
  require 'bundler/setup'
2
2
  require 'openai'
3
3
  require 'httparty'
4
- require 'dotenv'
5
4
  require 'pathname'
6
5
  require 'optparse'
7
6
 
8
7
  require_relative 'markdown_parser'
9
8
 
10
- Dotenv.load
11
-
12
-
13
9
  class Gromit::Uploader
14
10
 
15
11
  class << self
@@ -25,7 +21,7 @@ class Gromit::Uploader
25
21
  end.parse!
26
22
 
27
23
  path = Pathname.new(options.fetch(:source_dir, ''))
28
-
24
+
29
25
  unless path.exist?
30
26
  puts "Error: The source directory (-s or --source) doesn't exist or is not specified."
31
27
  exit 1
@@ -1,3 +1,3 @@
1
1
  module Gromit
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/gromit.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "gromit/version"
2
- require "gromit/engine"
3
2
  require "gromit/markdown_parser"
4
3
 
5
4
  module Gromit
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gromit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
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-08 00:00:00.000000000 Z
11
+ date: 2023-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: dotenv
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rails
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 7.0.1
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 7.0.1
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: redis
57
43
  requirement: !ruby/object:Gem::Requirement