2023-03-31 14:29:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class EmbeddingsGenerationStubs
|
|
|
|
class << self
|
|
|
|
def discourse_service(model, string, embedding)
|
2024-01-11 12:16:25 -05:00
|
|
|
model = "bge-large-en-v1.5" if model == "bge-large-en"
|
2023-03-31 14:29:56 -04:00
|
|
|
WebMock
|
|
|
|
.stub_request(
|
|
|
|
:post,
|
|
|
|
"#{SiteSetting.ai_embeddings_discourse_service_api_endpoint}/api/v1/classify",
|
|
|
|
)
|
|
|
|
.with(body: JSON.dump({ model: model, content: string }))
|
|
|
|
.to_return(status: 200, body: JSON.dump(embedding))
|
|
|
|
end
|
|
|
|
|
2024-02-04 19:16:36 -05:00
|
|
|
def openai_service(model, string, embedding, extra_args: {})
|
2023-03-31 14:29:56 -04:00
|
|
|
WebMock
|
|
|
|
.stub_request(:post, "https://api.openai.com/v1/embeddings")
|
2024-02-04 19:16:36 -05:00
|
|
|
.with(body: JSON.dump({ model: model, input: string }.merge(extra_args)))
|
2023-03-31 14:29:56 -04:00
|
|
|
.to_return(status: 200, body: JSON.dump({ data: [{ embedding: embedding }] }))
|
|
|
|
end
|
2024-12-10 13:42:31 -05:00
|
|
|
|
|
|
|
def gemini_service(api_key, string, embedding)
|
|
|
|
WebMock
|
|
|
|
.stub_request(
|
|
|
|
:post,
|
|
|
|
"https://generativelanguage.googleapis.com/v1beta/models/embedding-001:embedContent\?key\=#{api_key}",
|
|
|
|
)
|
|
|
|
.with(body: JSON.dump({ content: { parts: [{ text: string }] } }))
|
|
|
|
.to_return(status: 200, body: JSON.dump({ embedding: { values: embedding } }))
|
|
|
|
end
|
2023-03-31 14:29:56 -04:00
|
|
|
end
|
|
|
|
end
|