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.
21 lines
495 B
Ruby
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
|