mirror of
				https://github.com/discourse/discourse-ai.git
				synced 2025-10-31 06:28:48 +00:00 
			
		
		
		
	* FEATURE: Tweak HyDE prompts for better grounding in forum subject and limit response size * fix test * lint
		
			
				
	
	
		
			32 lines
		
	
	
		
			855 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			855 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| # frozen_string_literal: true
 | |
| 
 | |
| module DiscourseAi
 | |
|   module Embeddings
 | |
|     module HydeGenerators
 | |
|       class OpenAi < DiscourseAi::Embeddings::HydeGenerators::Base
 | |
|         def prompt(search_term)
 | |
|           [
 | |
|             {
 | |
|               role: "system",
 | |
|               content: "You are a helpful bot. You create forum posts about a given subject.",
 | |
|             },
 | |
|             { role: "user", content: "#{basic_prompt_instruction}\n#{search_term}" },
 | |
|           ]
 | |
|         end
 | |
| 
 | |
|         def models
 | |
|           %w[gpt-3.5-turbo gpt-4]
 | |
|         end
 | |
| 
 | |
|         def hypothetical_post_from(query)
 | |
|           ::DiscourseAi::Inference::OpenAiCompletions.perform!(
 | |
|             prompt(query),
 | |
|             SiteSetting.ai_embeddings_semantic_search_hyde_model,
 | |
|             max_tokens: 400,
 | |
|           ).dig(:choices, 0, :message, :content)
 | |
|         end
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| end
 |