Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Always raise the same exception/Open AI models migration #1087

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading