| 
									
										
										
										
											2023-05-20 17:45:54 +10:00
										 |  |  | #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) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-22 12:09:14 +10:00
										 |  |  |       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) | 
					
						
							| 
									
										
										
										
											2023-08-04 09:37:58 +10:00
										 |  |  |       info = summarizer.process(topic_id: post.topic_id, guidance: "why did it happen?") | 
					
						
							| 
									
										
										
										
											2023-05-20 17:45:54 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-22 12:09:14 +10:00
										 |  |  |       expect(info).to include("Topic summarized") | 
					
						
							|  |  |  |       expect(summarizer.custom_raw).to include("summary stuff") | 
					
						
							|  |  |  |       expect(summarizer.chain_next_response).to eq(false) | 
					
						
							| 
									
										
										
										
											2023-05-20 17:45:54 +10:00
										 |  |  |     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) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-22 12:09:14 +10:00
										 |  |  |       summarizer = described_class.new(bot_user, post) | 
					
						
							| 
									
										
										
										
											2023-08-04 09:37:58 +10:00
										 |  |  |       info = summarizer.process(topic_id: post.topic_id, guidance: "why did it happen?") | 
					
						
							| 
									
										
										
										
											2023-05-20 17:45:54 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(info).not_to include(post.raw) | 
					
						
							| 
									
										
										
										
											2023-05-22 12:09:14 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(summarizer.custom_raw).to eq(I18n.t("discourse_ai.ai_bot.topic_not_found")) | 
					
						
							| 
									
										
										
										
											2023-05-20 17:45:54 +10:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |