FIX: Always raise the single exception/Open AI models migration (#1087)
This commit is contained in:
parent
d5cf53e8e0
commit
5a97752117
|
@ -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?
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue