mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-10-25 19:48:42 +00:00
Also fixes it so users without bot in header can send it messages. Previous to this change we would seed all bots with database seeds. This lead to lots of confusion for people who do not enable ai bot. Instead: 1. We do not seed any bots **until** user enables the ai_bot_enabled setting 2. If it is disabled we will a. If no messages were created by bot - delete it b. Otherwise we will deactivate account
40 lines
1.2 KiB
Ruby
40 lines
1.2 KiB
Ruby
#frozen_string_literal: true
|
|
|
|
require_relative "../../../../support/openai_completions_inference_stubs"
|
|
|
|
RSpec.describe DiscourseAi::AiBot::Commands::Command do
|
|
let(:bot_user) { User.find(DiscourseAi::AiBot::EntryPoint::GPT3_5_TURBO_ID) }
|
|
let(:command) { DiscourseAi::AiBot::Commands::GoogleCommand.new(bot_user: bot_user, args: nil) }
|
|
|
|
before { SiteSetting.ai_bot_enabled = true }
|
|
|
|
describe "#format_results" do
|
|
it "can generate efficient tables of data" do
|
|
rows = [1, 2, 3, 4, 5]
|
|
column_names = %w[first second third]
|
|
|
|
formatted =
|
|
command.format_results(rows, column_names) { |row| ["row ¦ 1", row + 1, "a|b,\nc"] }
|
|
|
|
expect(formatted[:column_names].length).to eq(3)
|
|
expect(formatted[:rows].length).to eq(5)
|
|
expect(formatted.to_s).to include("a|b,\\nc")
|
|
end
|
|
|
|
it "can also generate results by returning hash per row" do
|
|
rows = [1, 2, 3, 4, 5]
|
|
column_names = %w[first second third]
|
|
|
|
formatted =
|
|
command.format_results(rows, column_names) { |row| ["row ¦ 1", row + 1, "a|b,\nc"] }
|
|
|
|
formatted2 =
|
|
command.format_results(rows) do |row|
|
|
{ first: "row ¦ 1", second: row + 1, third: "a|b,\nc" }
|
|
end
|
|
|
|
expect(formatted).to eq(formatted2)
|
|
end
|
|
end
|
|
end
|