Skip to content

Commit

Permalink
FIX: Always raise the single exception/Open AI models migration (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanrizzi authored Jan 23, 2025
1 parent d5cf53e commit 5a97752
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def creds_for(provider)

# Open AI
elsif provider == "open_ai"
endpoint = fetch_setting("ai_openai_embeddings_url")
endpoint = fetch_setting("ai_openai_embeddings_url") || "https://api.openai.com/v1/embeddings"
api_key = fetch_setting("ai_openai_api_key")

return if endpoint.blank? || api_key.blank?
Expand Down
7 changes: 3 additions & 4 deletions lib/embeddings/semantic_related.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
module DiscourseAi
module Embeddings
class SemanticRelated
MissingEmbeddingError = Class.new(StandardError)

def self.clear_cache_for(topic)
Discourse.cache.delete("semantic-suggested-topic-#{topic.id}")
Discourse.redis.del("build-semantic-suggested-topic-#{topic.id}")
Expand All @@ -26,11 +24,12 @@ def related_topic_ids_for(topic)
# Happens when the topic doesn't have any embeddings
# I'd rather not use Exceptions to control the flow, so this should be refactored soon
if candidate_ids.empty? || !candidate_ids.include?(topic.id)
raise MissingEmbeddingError, "No embeddings found for topic #{topic.id}"
raise ::DiscourseAi::Embeddings::Schema::MissingEmbeddingError,
"No embeddings found for topic #{topic.id}"
end
end
end
rescue MissingEmbeddingError
rescue ::DiscourseAi::Embeddings::Schema::MissingEmbeddingError
# avoid a flood of jobs when visiting topic
if Discourse.redis.set(
build_semantic_suggested_key(topic.id),
Expand Down

0 comments on commit 5a97752

Please sign in to comment.