2023-11-17 15:46:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "AI Composer helper", type: :system, js: true do
|
|
|
|
let(:search_page) { PageObjects::Pages::Search.new }
|
|
|
|
let(:query) { "apple_pie" }
|
|
|
|
let(:hypothetical_post) { "This is an hypothetical post generated from the keyword apple_pie" }
|
|
|
|
|
|
|
|
fab!(:user) { Fabricate(:admin) }
|
2024-03-05 10:48:28 -05:00
|
|
|
fab!(:topic)
|
2023-11-17 15:46:59 -05:00
|
|
|
fab!(:post) { Fabricate(:post, topic: topic, raw: "Apple pie is a delicious dessert to eat") }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.ai_embeddings_discourse_service_api_endpoint = "http://test.com"
|
|
|
|
prompt = DiscourseAi::Embeddings::HydeGenerators::OpenAi.new.prompt(query)
|
|
|
|
OpenAiCompletionsInferenceStubs.stub_response(
|
|
|
|
prompt,
|
|
|
|
hypothetical_post,
|
|
|
|
req_opts: {
|
|
|
|
max_tokens: 400,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
hyde_embedding = [0.049382, 0.9999]
|
|
|
|
EmbeddingsGenerationStubs.discourse_service(
|
|
|
|
SiteSetting.ai_embeddings_model,
|
|
|
|
hypothetical_post,
|
|
|
|
hyde_embedding,
|
|
|
|
)
|
|
|
|
|
|
|
|
SearchIndexer.enable
|
|
|
|
SearchIndexer.index(topic, force: true)
|
|
|
|
SiteSetting.ai_embeddings_semantic_search_enabled = true
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
described_class.clear_cache_for(query)
|
|
|
|
SearchIndexer.disable
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when performing a search in the full page search page" do
|
2024-01-19 06:51:26 -05:00
|
|
|
skip "TODO: Implement test after doing LLM abstraction" do
|
2023-11-17 15:46:59 -05:00
|
|
|
it "performs AI search in the background and hides results by default" do
|
|
|
|
visit("/search?expanded=true")
|
|
|
|
search_page.type_in_search("apple pie")
|
|
|
|
search_page.click_search_button
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|