2023-02-24 11:25:02 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative "../../../support/sentiment_inference_stubs"
|
|
|
|
|
2023-03-14 15:03:50 -04:00
|
|
|
describe DiscourseAi::Sentiment::SentimentClassification do
|
2023-02-27 14:21:40 -05:00
|
|
|
fab!(:target) { Fabricate(:post) }
|
2023-02-24 11:25:02 -05:00
|
|
|
|
2023-02-27 14:21:40 -05:00
|
|
|
describe "#request" do
|
2024-11-04 07:14:34 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.ai_sentiment_model_configs =
|
|
|
|
"[{\"model_name\":\"SamLowe/roberta-base-go_emotions\",\"endpoint\":\"http://samlowe-emotion.com\",\"api_key\":\"123\"},{\"model_name\":\"j-hartmann/emotion-english-distilroberta-base\",\"endpoint\":\"http://jhartmann-emotion.com\",\"api_key\":\"123\"},{\"model_name\":\"cardiffnlp/twitter-roberta-base-sentiment-latest\",\"endpoint\":\"http://cardiffnlp-sentiment.com\",\"api_key\":\"123\"}]"
|
|
|
|
end
|
2023-02-24 11:25:02 -05:00
|
|
|
|
|
|
|
it "returns the classification and the model used for it" do
|
|
|
|
SentimentInferenceStubs.stub_classification(target)
|
|
|
|
|
|
|
|
result = subject.request(target)
|
|
|
|
|
2024-11-04 07:14:34 -05:00
|
|
|
subject.available_classifiers.each do |model_config|
|
|
|
|
expect(result[model_config.model_name]).to eq(
|
|
|
|
subject.transform_result(SentimentInferenceStubs.model_response(model_config.model_name)),
|
|
|
|
)
|
2023-02-24 11:25:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|