Files
leadchat/enterprise/app/services/captain/llm/embedding_service.rb
Pranav ecfa6bf6a2 feat: Add support for account abuse detection (#11001)
This PR adds service to automate account abuse detection. Currently
based on the signup name and URL, could potentially add more context
such as usage analysis, message metadata etc.
2025-02-28 15:28:19 -08:00

21 lines
495 B
Ruby

require 'openai'
class Captain::Llm::EmbeddingService < Llm::BaseOpenAiService
class EmbeddingsError < StandardError; end
DEFAULT_MODEL = 'text-embedding-3-small'.freeze
def get_embedding(content, model: DEFAULT_MODEL)
response = @client.embeddings(
parameters: {
model: model,
input: content
}
)
response.dig('data', 0, 'embedding')
rescue StandardError => e
raise EmbeddingsError, "Failed to create an embedding: #{e.message}"
end
end