Skip to content

Commit

Permalink
Better logs messages!
Browse files Browse the repository at this point in the history
The Jekyll logger supports a topic, we should use it!
  • Loading branch information
mkasberg committed May 16, 2024
1 parent 03cfcd4 commit de39128
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/jekyll_ai_related_posts/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
module JekyllAiRelatedPosts
class Generator < Jekyll::Generator
def generate(site)
Jekyll.logger.info "AI Related Posts:", "Generating related posts..."

@site = site
setup_database

Expand All @@ -18,7 +20,6 @@ def generate(site)
end

if fetch_enabled?
Jekyll.logger.info "[ai_related_posts] Generating related posts..."
@embeddings_fetcher = new_fetcher

@site.posts.docs.each do |p|
Expand All @@ -29,7 +30,7 @@ def generate(site)
find_related(p)
end
else
Jekyll.logger.info "[ai_related_posts] Using cached related posts data..."
Jekyll.logger.info "AI Related Posts:", "Fetch disabled. Using cached related posts data."

@site.posts.docs.each do |p|
fallback_generate_related(p)
Expand Down Expand Up @@ -139,7 +140,7 @@ def embedding_text(post)
end

def embedding_for(post)
Jekyll.logger.info "[ai_related_posts] Fetching embedding for #{post.relative_path}"
Jekyll.logger.info "AI Related Posts:", "Fetching embedding for #{post.relative_path}"
input = embedding_text(post)

@embeddings_fetcher.embedding_for(input)
Expand Down Expand Up @@ -175,7 +176,7 @@ def setup_database
SQL
ActiveRecord::Base.connection.execute(create_vss_posts)

Jekyll.logger.debug("ai_related_posts db setup complete")
Jekyll.logger.debug "AI Related Posts:", "DB setup complete"
end
end
end
4 changes: 2 additions & 2 deletions lib/jekyll_ai_related_posts/open_ai_embeddings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def embedding_for(text)

res.body["data"].first["embedding"]
rescue Faraday::Error => e
Jekyll.logger.error "Error response from OpanAI API!"
Jekyll.logger.error e.inspect
Jekyll.logger.error "AI Related Posts:", "Error response from OpenAI API!"
Jekyll.logger.error "AI Related Posts:", e.inspect

raise
end
Expand Down

0 comments on commit de39128

Please sign in to comment.