mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-06 17:30:20 +00:00
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
|
class Anthropic < DiscourseAi::Embeddings::HydeGenerators::Base
|
||||||
def prompt(search_term)
|
def prompt(search_term)
|
||||||
<<~TEXT
|
<<~TEXT
|
||||||
Given a search term given between <input> tags, generate a forum post about a given subject.
|
Human: Given a search term given between <input> tags, generate a forum post about a given subject.
|
||||||
#{basic_prompt_instruction}
|
#{basic_prompt_instruction}
|
||||||
<input>#{search_term}</input>
|
<input>#{search_term}</input>
|
||||||
|
|
||||||
Respond with the generated post between <ai> tags.
|
Respond with the generated post between <ai> tags.
|
||||||
TEXT
|
|
||||||
|
Assistant:\n
|
||||||
|
TEXT
|
||||||
end
|
end
|
||||||
|
|
||||||
def models
|
def models
|
||||||
@ -24,6 +26,7 @@ module DiscourseAi
|
|||||||
prompt(query),
|
prompt(query),
|
||||||
SiteSetting.ai_embeddings_semantic_search_hyde_model,
|
SiteSetting.ai_embeddings_semantic_search_hyde_model,
|
||||||
max_tokens: 400,
|
max_tokens: 400,
|
||||||
|
stop_sequences: ["</ai>"],
|
||||||
).dig(:completion)
|
).dig(:completion)
|
||||||
|
|
||||||
Nokogiri::HTML5.fragment(response).at("ai").text
|
Nokogiri::HTML5.fragment(response).at("ai").text
|
||||||
|
@ -12,7 +12,8 @@ module ::DiscourseAi
|
|||||||
temperature: nil,
|
temperature: nil,
|
||||||
top_p: nil,
|
top_p: nil,
|
||||||
max_tokens: nil,
|
max_tokens: nil,
|
||||||
user_id: nil
|
user_id: nil,
|
||||||
|
stop_sequences: nil
|
||||||
)
|
)
|
||||||
log = nil
|
log = nil
|
||||||
response_data = +""
|
response_data = +""
|
||||||
@ -31,6 +32,7 @@ module ::DiscourseAi
|
|||||||
payload[:max_tokens_to_sample] = max_tokens || 2000
|
payload[:max_tokens_to_sample] = max_tokens || 2000
|
||||||
payload[:temperature] = temperature if temperature
|
payload[:temperature] = temperature if temperature
|
||||||
payload[:stream] = true if block_given?
|
payload[:stream] = true if block_given?
|
||||||
|
payload[:stop_sequences] = stop_sequences if stop_sequences
|
||||||
|
|
||||||
Net::HTTP.start(
|
Net::HTTP.start(
|
||||||
url.host,
|
url.host,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user