discourse/plugins/discourse-ai/spec/lib/agents/sentiment_classifier_spec.rb
Rafael dos Santos Silva 2be96e2098
FEATURE: Add agent-backed sentiment classification (#40136)
Previously, sentiment and emotion classification only used configured
classification model endpoints, which blocked sites that could not run
those models.

This change lets admins choose agent-backed LLM classifiers for
sentiment and emotion while storing results under stable model keys so
LLM changes do not force historic reclassification.
2026-05-26 10:32:54 -03:00

29 lines
783 B
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe DiscourseAi::Agents::SentimentClassifier do
subject(:agent) { described_class.new }
before { enable_current_plugin }
describe "#system_prompt" do
it "describes probability score constraints" do
prompt = agent.system_prompt
expect(prompt).to include("float from 0 to 1")
expect(prompt).to include("sum to 1.0")
end
end
describe "#examples" do
it "uses valid sentiment probability distributions" do
labels = %w[negative neutral positive]
agent.examples.each do |_input, output|
parsed_output = JSON.parse(output)
expect(parsed_output.keys).to contain_exactly(*labels)
expect(parsed_output.values.sum).to be_within(0.001).of(1.0)
end
end
end
end