mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-09 11:48:47 +00:00
* Use AR model for embeddings features * endpoints * Embeddings CRUD UI * Add presets. Hide a couple more settings * system specs * Seed embedding definition from old settings * Generate search bit index on the fly. cleanup orphaned data * support for seeded models * Fix run test for new embedding * fix selected model not set correctly
62 lines
1.7 KiB
Ruby
62 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe DiscourseAi::Inference::OpenAiEmbeddings do
|
|
let(:api_key) { "123456" }
|
|
let(:dimensions) { 1000 }
|
|
let(:model) { "text-embedding-ada-002" }
|
|
|
|
it "supports azure embeddings" do
|
|
azure_url =
|
|
"https://my-company.openai.azure.com/openai/deployments/embeddings-deployment/embeddings?api-version=2023-05-15"
|
|
|
|
body_json = {
|
|
usage: {
|
|
prompt_tokens: 1,
|
|
total_tokens: 1,
|
|
},
|
|
data: [{ object: "embedding", embedding: [0.0, 0.1] }],
|
|
}.to_json
|
|
|
|
stub_request(:post, azure_url).with(
|
|
body: "{\"model\":\"text-embedding-ada-002\",\"input\":\"hello\"}",
|
|
headers: {
|
|
"Api-Key" => api_key,
|
|
"Content-Type" => "application/json",
|
|
},
|
|
).to_return(status: 200, body: body_json, headers: {})
|
|
|
|
result =
|
|
DiscourseAi::Inference::OpenAiEmbeddings.new(azure_url, api_key, model, nil).perform!("hello")
|
|
|
|
expect(result).to eq([0.0, 0.1])
|
|
end
|
|
|
|
it "supports openai embeddings" do
|
|
url = "https://api.openai.com/v1/embeddings"
|
|
body_json = {
|
|
usage: {
|
|
prompt_tokens: 1,
|
|
total_tokens: 1,
|
|
},
|
|
data: [{ object: "embedding", embedding: [0.0, 0.1] }],
|
|
}.to_json
|
|
|
|
body = { model: model, input: "hello", dimensions: dimensions }.to_json
|
|
|
|
stub_request(:post, url).with(
|
|
body: body,
|
|
headers: {
|
|
"Authorization" => "Bearer #{api_key}",
|
|
"Content-Type" => "application/json",
|
|
},
|
|
).to_return(status: 200, body: body_json, headers: {})
|
|
|
|
result =
|
|
DiscourseAi::Inference::OpenAiEmbeddings.new(url, api_key, model, dimensions).perform!(
|
|
"hello",
|
|
)
|
|
|
|
expect(result).to eq([0.0, 0.1])
|
|
end
|
|
end
|