jekyll_ai_related_posts 0.1.0 → 0.1.2

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: 8b59977a0c1d912e06792f7123c7d443547f1decb9fdf4042d90a4fcd4e1eb4e
4
- data.tar.gz: 159db1306777a201cff3a9d3532ddba444164dbfb780207fb9457ce4898df5f8
3
+ metadata.gz: dde47b3847f5f2578a80f8f208049f912d409e7812a2927dda4ea333b0b8cd82
4
+ data.tar.gz: 9d94d4dd9695b96467349818d20f961ac9a55f9bd5c4968c3703636854d71edb
5
5
  SHA512:
6
- metadata.gz: e0f73857997bdacd22059c542a1d2a642a3ea76aa165241c155a0e8b2cafdc4f48607f334a2ed7a265a252e86969d9e523bf4ef2ac5889e1f39c36d1a27792f5
7
- data.tar.gz: a5f5f573459deb7fab308b1fb98a1d60ce1aeda95e28860161ed886a3ab90c43f1b7d36fea6cc5c570b05cd15284a59240e8676f5b10f44290b05fbacbd379df
6
+ metadata.gz: 857d8f3e381b1f4f3d52c411cc5ab630f4539ab735df57b33276f5b9df0647bebe44319b3a8a2a647f75cc3910409863aeae56d412dd48827fa5116870ea7975
7
+ data.tar.gz: eab136bfd7e226dcc0dfd71c14a0a9924b5e3aa59f8c376200129b3237e39f7e47ce540d55d03a080d834ebe56306b5827de44d8e55b9f04e71aedfbc3c9b60a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-04-18
3
+ - [Bugfix] Include up to 10 related posts (like native Jekyll does) instead of just 3.
4
+
5
+ ## [0.1.1] - 2024-04-23
6
+
7
+ - [Bugfix] Exception when running in cache-only mode.
8
+
9
+ ## [0.1.0] - 2024-04-23
4
10
 
5
11
  - Initial release
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Jekyll AI Related Posts 🪄
2
2
 
3
+ Rubygems: [jekyll_ai_related_posts](https://rubygems.org/gems/jekyll_ai_related_posts)
4
+
3
5
  Jekyll ships with functionality that populates
4
6
  [related_posts](https://jekyllrb.com/docs/variables/) with the ten most recent
5
7
  posts. If you install
@@ -18,7 +20,22 @@ posts with the accuracy of OpenAI's models (or any other LLM, for that matter).
18
20
 
19
21
  Jekyll AI Related Posts is a [Jekyll
20
22
  plugin](https://jekyllrb.com/docs/plugins/installation/). It can be installed
21
- using any Jekyll plugin installation method.
23
+ using any Jekyll plugin installation method. For example, in your `_config.yml`:
24
+
25
+ ```yaml
26
+ plugins:
27
+ - jekyll_ai_related_posts
28
+ ```
29
+
30
+ You should also ignore the cache files that this plugin generates. (This will
31
+ help avoid a regeneration loop when using `jekyll serve`.)
32
+
33
+ ```yaml
34
+ exclude:
35
+ - .ai_related_posts_cache.sqlite3
36
+ - .ai_related_posts_cache.sqlite3-journal
37
+ ```
38
+
22
39
 
23
40
  ## Configuration
24
41
 
@@ -57,6 +74,27 @@ to use it:
57
74
  </ul>
58
75
  ```
59
76
 
77
+ ### First Run
78
+
79
+ The first time the plugin runs, it will fetch embeddings for all your posts.
80
+ Based on some light testing, this took me 0.5 sec per post, or about 50 sec for
81
+ a blog with 100 posts. All subsequent runs will be faster since embeddings will
82
+ be cached.
83
+
84
+ ### Performance
85
+
86
+ On an example blog with ~100 posts, this plugin produces more accurate results
87
+ than classifier-reborn (LSI) in about the same amount of time. See [this blog
88
+ post](https://www.mikekasberg.com/blog/2024/04/23/better-related-posts-in-jekyll-using-ai.html)
89
+ for details.
90
+
91
+ ### Cost
92
+
93
+ The API costs to use this plugin with OpenAI's API are minimal. I ran this
94
+ plugin for all 84 posts on [mikekasberg.com](https://www.mikekasberg.com) for
95
+ $0.00 in API fees (1,277 tokens on the text-embedding-3-small model). (Your
96
+ results may vary, but should remain inexpensive.)
97
+
60
98
  ### Upgrading from Built-In Related Posts
61
99
 
62
100
  If you're already using Jekyll's built-in `site.related_posts` and you want to
@@ -68,6 +106,17 @@ upgrade to AI related posts:
68
106
  option to the `jekyll` command. You can remove the `classifier-reborn` gem and
69
107
  its dependencies (Numo).
70
108
 
109
+ ### Cache File (.ai_related_posts_cache.sqlite3)
110
+
111
+ This plugin will cache embeddings in `.ai_related_posts_cache.sqlite3` in your
112
+ Jekyll source root (typically the root of your project directory). The file
113
+ itself is a SQLite database file. For most cases, I'd recommend adding this file
114
+ to your `.gitignore` since it's a binary cache file. However, you _may_ choose
115
+ to check it in to git if, for example, you want to share cached embeddings
116
+ across many machines (and are willing to check in a binary file on the order of
117
+ 1-10Mb to do so). If the file is not present, it will be re-created and
118
+ embeddings will be fetched from the API (which may result in higher API usage
119
+ fees if done frequently).
71
120
 
72
121
  ## How It Works
73
122
 
@@ -88,10 +137,9 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
88
137
  `rake spec` to run the tests. You can also run `bin/console` for an interactive
89
138
  prompt that will allow you to experiment.
90
139
 
91
- To install this gem onto your local machine, run `bundle exec rake install`. To
92
- release a new version, update the version number in `version.rb`, and then run
93
- `bundle exec rake release`, which will create a git tag for the version, push
94
- git commits and the created tag, and push the `.gem` file to
140
+ To release a new version, update the version number in `version.rb`, and then
141
+ run `bundle exec rake release`, which will create a git tag for the version,
142
+ push git commits and the created tag, and push the `.gem` file to
95
143
  [rubygems.org](https://rubygems.org).
96
144
 
97
145
  ## Contributing
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in jekyll_ai_related_posts.gemspec
6
+ gemspec path: '../'
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+ gem "rubocop-rails-omakase", require: false
14
+
15
+ gem "debug"
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "jekyll", "~> 3.9"
6
+ gem "kramdown-parser-gfm"
7
+
8
+ # Specify your gem's dependencies in jekyll_ai_related_posts.gemspec
9
+ gemspec path: '../'
10
+
11
+ gem "rake", "~> 13.0"
12
+
13
+ gem "rspec", "~> 3.0"
14
+
15
+ gem "rubocop", "~> 1.21"
16
+ gem "rubocop-rails-omakase", require: false
17
+
18
+ gem "debug"
@@ -12,6 +12,11 @@ module JekyllAiRelatedPosts
12
12
  @site = site
13
13
  setup_database
14
14
 
15
+ @indexed_posts = {}
16
+ site.posts.docs.each do |p|
17
+ @indexed_posts[p.relative_path] = p
18
+ end
19
+
15
20
  if fetch_enabled?
16
21
  Jekyll.logger.info "[ai_related_posts] Generating related posts..."
17
22
  @embeddings_fetcher = new_fetcher
@@ -20,11 +25,6 @@ module JekyllAiRelatedPosts
20
25
  ensure_embedding_cached(p)
21
26
  end
22
27
 
23
- @indexed_posts = {}
24
- site.posts.docs.each do |p|
25
- @indexed_posts[p.relative_path] = p
26
- end
27
-
28
28
  @site.posts.docs.each do |p|
29
29
  find_related(p)
30
30
  end
@@ -111,7 +111,7 @@ module JekyllAiRelatedPosts
111
111
  relative_path: post.relative_path
112
112
  } ]))
113
113
  # The first result is the post itself, with a distance of 0.
114
- rowids = results.sort_by { |r| r["distance"] }.drop(1).first(3).map { |r| r["rowid"] }
114
+ rowids = results.sort_by { |r| r["distance"] }.drop(1).first(10).map { |r| r["rowid"] }
115
115
 
116
116
  posts_by_rowid = {}
117
117
  rowids.each do |rowid|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllAiRelatedPosts
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_ai_related_posts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Kasberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-23 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '7.1'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '7.1'
26
+ version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +107,8 @@ files:
107
107
  - LICENSE.txt
108
108
  - README.md
109
109
  - Rakefile
110
+ - gemfiles/current.gemfile
111
+ - gemfiles/jekyll3.gemfile
110
112
  - lib/jekyll_ai_related_posts.rb
111
113
  - lib/jekyll_ai_related_posts/generator.rb
112
114
  - lib/jekyll_ai_related_posts/models/post.rb
@@ -119,7 +121,7 @@ metadata:
119
121
  allowed_push_host: https://rubygems.org
120
122
  homepage_uri: https://github.com/mkasberg/jekyll_ai_related_posts
121
123
  source_code_uri: https://github.com/mkasberg/jekyll_ai_related_posts
122
- changelog_uri: https://github.com/mkasberg/jekyll_ai_related_posts
124
+ changelog_uri: https://github.com/mkasberg/jekyll_ai_related_posts/blob/main/CHANGELOG.md
123
125
  post_install_message:
124
126
  rdoc_options: []
125
127
  require_paths: