FEATURE: Use stop_sequences for faster HyDE searches with Claude (#203)

This commit is contained in:
Rafael dos Santos Silva 2023-09-06 10:06:31 -03:00 committed by GitHub
parent 13d63f1f30
commit 5c50d2aa09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -6,11 +6,13 @@ 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.
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.
Assistant:\n
TEXT
end
@ -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

View File

@ -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,