mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 05:35:40 +08:00
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.
29 lines
783 B
Ruby
Vendored
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
|