mirror of
				https://github.com/discourse/discourse-ai.git
				synced 2025-10-31 14:38:37 +00:00 
			
		
		
		
	* FEATURE: introduce a more efficient formatter Previous formatting style was space inefficient given JSON consumes lots of tokens, the new format is now used consistently across commands Also fixes - search limited to 10 - search breaking on limit: non existent directive * Slight improvement to summarizer Stop blowing up context with custom prompts * ensure we include the guiding message * correct spec * langchain style summarizer ... much more accurate (albeit more expensive) * lint
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| #frozen_string_literal: true
 | |
| 
 | |
| require_relative "../../../../support/openai_completions_inference_stubs"
 | |
| 
 | |
| RSpec.describe DiscourseAi::AiBot::Commands::SummarizeCommand do
 | |
|   fab!(:bot_user) { User.find(DiscourseAi::AiBot::EntryPoint::GPT3_5_TURBO_ID) }
 | |
| 
 | |
|   describe "#process" do
 | |
|     it "can generate correct info" do
 | |
|       post = Fabricate(:post)
 | |
| 
 | |
|       WebMock.stub_request(:post, "https://api.openai.com/v1/chat/completions").to_return(
 | |
|         status: 200,
 | |
|         body: JSON.dump({ choices: [{ message: { content: "summary stuff" } }] }),
 | |
|       )
 | |
| 
 | |
|       summarizer = described_class.new(bot_user, post)
 | |
|       info = summarizer.process("#{post.topic_id} why did it happen?")
 | |
| 
 | |
|       expect(info).to include("Topic summarized")
 | |
|       expect(summarizer.custom_raw).to include("summary stuff")
 | |
|       expect(summarizer.chain_next_response).to eq(false)
 | |
|     end
 | |
| 
 | |
|     it "protects hidden data" do
 | |
|       category = Fabricate(:category)
 | |
|       category.set_permissions({})
 | |
|       category.save!
 | |
| 
 | |
|       topic = Fabricate(:topic, category_id: category.id)
 | |
|       post = Fabricate(:post, topic: topic)
 | |
| 
 | |
|       summarizer = described_class.new(bot_user, post)
 | |
|       info = summarizer.process("#{post.topic_id} why did it happen?")
 | |
| 
 | |
|       expect(info).not_to include(post.raw)
 | |
| 
 | |
|       expect(summarizer.custom_raw).to eq(I18n.t("discourse_ai.ai_bot.topic_not_found"))
 | |
|     end
 | |
|   end
 | |
| end
 |