FEATURE: Use stop_sequences for faster HyDE searches with Claude (#203)
This commit is contained in:
parent
13d63f1f30
commit
5c50d2aa09
|
@ -6,12 +6,14 @@ module DiscourseAi
|
|||
class Anthropic < DiscourseAi::Embeddings::HydeGenerators::Base
|
||||
def prompt(search_term)
|
||||
<<~TEXT
|
||||
Given a search term given between <input> tags, generate a forum post about a given subject.
|
||||
#{basic_prompt_instruction}
|
||||
<input>#{search_term}</input>
|
||||
Human: Given a search term given between <input> tags, generate a forum post about a given subject.
|
||||
#{basic_prompt_instruction}
|
||||
<input>#{search_term}</input>
|
||||
|
||||
Respond with the generated post between <ai> tags.
|
||||
TEXT
|
||||
Respond with the generated post between <ai> tags.
|
||||
|
||||
Assistant:\n
|
||||
TEXT
|
||||
end
|
||||
|
||||
def models
|
||||
|
@ -24,6 +26,7 @@ module DiscourseAi
|
|||
prompt(query),
|
||||
SiteSetting.ai_embeddings_semantic_search_hyde_model,
|
||||
max_tokens: 400,
|
||||
stop_sequences: ["</ai>"],
|
||||
).dig(:completion)
|
||||
|
||||
Nokogiri::HTML5.fragment(response).at("ai").text
|
||||
|
|
|
@ -12,7 +12,8 @@ module ::DiscourseAi
|
|||
temperature: nil,
|
||||
top_p: nil,
|
||||
max_tokens: nil,
|
||||
user_id: nil
|
||||
user_id: nil,
|
||||
stop_sequences: nil
|
||||
)
|
||||
log = nil
|
||||
response_data = +""
|
||||
|
@ -31,6 +32,7 @@ module ::DiscourseAi
|
|||
payload[:max_tokens_to_sample] = max_tokens || 2000
|
||||
payload[:temperature] = temperature if temperature
|
||||
payload[:stream] = true if block_given?
|
||||
payload[:stop_sequences] = stop_sequences if stop_sequences
|
||||
|
||||
Net::HTTP.start(
|
||||
url.host,
|
||||
|
|
Loading…
Reference in New Issue