mirror of
				https://github.com/discourse/discourse-ai.git
				synced 2025-10-31 06:28:48 +00:00 
			
		
		
		
	Introduce a Discourse Automation based periodical report. Depends on Discourse Automation. Report works best with very large context language models such as GPT-4-Turbo and Claude 2. - Introduces final_insts to generic llm format, for claude to work best it is better to guide the last assistant message (we should add this to other spots as well) - Adds GPT-4 turbo support to generic llm interface
		
			
				
	
	
		
			86 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # frozen_string_literal: true
 | |
| describe DiscourseAi::Automation::LlmTriage do
 | |
|   fab!(:post) { Fabricate(:post) }
 | |
| 
 | |
|   def triage(**args)
 | |
|     DiscourseAi::Automation::LlmTriage.handle(**args)
 | |
|   end
 | |
| 
 | |
|   it "does nothing if it does not pass triage" do
 | |
|     DiscourseAi::Completions::Llm.with_prepared_responses(["good"]) do
 | |
|       triage(
 | |
|         post: post,
 | |
|         model: "gpt-4",
 | |
|         hide_topic: true,
 | |
|         system_prompt: "test %%POST%%",
 | |
|         search_for_text: "bad",
 | |
|       )
 | |
|     end
 | |
| 
 | |
|     expect(post.topic.reload.visible).to eq(true)
 | |
|   end
 | |
| 
 | |
|   it "can hide topics on triage with claude" do
 | |
|     DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
 | |
|       triage(
 | |
|         post: post,
 | |
|         model: "claude-2",
 | |
|         hide_topic: true,
 | |
|         system_prompt: "test %%POST%%",
 | |
|         search_for_text: "bad",
 | |
|       )
 | |
|     end
 | |
| 
 | |
|     expect(post.topic.reload.visible).to eq(false)
 | |
|   end
 | |
| 
 | |
|   it "can hide topics on triage with claude" do
 | |
|     DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
 | |
|       triage(
 | |
|         post: post,
 | |
|         model: "gpt-4",
 | |
|         hide_topic: true,
 | |
|         system_prompt: "test %%POST%%",
 | |
|         search_for_text: "bad",
 | |
|       )
 | |
|     end
 | |
| 
 | |
|     expect(post.topic.reload.visible).to eq(false)
 | |
|   end
 | |
| 
 | |
|   it "can categorize topics on triage" do
 | |
|     category = Fabricate(:category)
 | |
| 
 | |
|     DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
 | |
|       triage(
 | |
|         post: post,
 | |
|         model: "gpt-4",
 | |
|         category_id: category.id,
 | |
|         system_prompt: "test %%POST%%",
 | |
|         search_for_text: "bad",
 | |
|       )
 | |
|     end
 | |
| 
 | |
|     expect(post.topic.reload.category_id).to eq(category.id)
 | |
|   end
 | |
| 
 | |
|   it "can reply to topics on triage" do
 | |
|     user = Fabricate(:user)
 | |
|     DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
 | |
|       triage(
 | |
|         post: post,
 | |
|         model: "gpt-4",
 | |
|         system_prompt: "test %%POST%%",
 | |
|         search_for_text: "bad",
 | |
|         canned_reply: "test canned reply 123",
 | |
|         canned_reply_user: user.username,
 | |
|       )
 | |
|     end
 | |
| 
 | |
|     reply = post.topic.posts.order(:post_number).last
 | |
| 
 | |
|     expect(reply.raw).to eq("test canned reply 123")
 | |
|     expect(reply.user.id).to eq(user.id)
 | |
|   end
 | |
| end
 |