FIX: Always raise the single exception/Open AI models migration (#1087)

This commit is contained in:
Roman Rizzi 2025-01-23 15:30:06 -03:00 committed by GitHub
parent d5cf53e8e0
commit 5a97752117
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View File

@ -90,7 +90,7 @@ class EmbeddingConfigDataMigration < ActiveRecord::Migration[7.0]
# 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?

View File

@ -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}")
@ -26,11 +24,12 @@ module DiscourseAi
# 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),