From 419c43592ab0990ace23e6eba91cf25aff98dcee Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Thu, 23 Nov 2023 16:33:37 -0300 Subject: [PATCH] FIX: Make summaries more cohesive by tweaking prompt. (#310) Other changes: - Don't use Bedrock for non claude models if credentials are set. - Remove extra sentence from HyDE prompt. --- lib/completions/endpoints/aws_bedrock.rb | 3 ++- lib/modules/embeddings/semantic_search.rb | 1 - .../summarization/strategies/fold_content.rb | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/completions/endpoints/aws_bedrock.rb b/lib/completions/endpoints/aws_bedrock.rb index aadeb401..84fe4f49 100644 --- a/lib/completions/endpoints/aws_bedrock.rb +++ b/lib/completions/endpoints/aws_bedrock.rb @@ -5,7 +5,8 @@ module DiscourseAi module Endpoints class AwsBedrock < Base def self.can_contact?(model_name) - SiteSetting.ai_bedrock_access_key_id.present? && + %w[claude-instant-1 claude-2].include?(model_name) && + SiteSetting.ai_bedrock_access_key_id.present? && SiteSetting.ai_bedrock_secret_access_key.present? && SiteSetting.ai_bedrock_region.present? end diff --git a/lib/modules/embeddings/semantic_search.rb b/lib/modules/embeddings/semantic_search.rb index b56004fe..87ee12fb 100644 --- a/lib/modules/embeddings/semantic_search.rb +++ b/lib/modules/embeddings/semantic_search.rb @@ -100,7 +100,6 @@ module DiscourseAi You are a content creator for a forum. The forum description is as follows: #{SiteSetting.title} #{SiteSetting.site_description} - Given the forum description write a forum post about the following subject: TEXT input: <<~TEXT, Using this description, write a forum post about the subject inside the XML tags: diff --git a/lib/modules/summarization/strategies/fold_content.rb b/lib/modules/summarization/strategies/fold_content.rb index 5c646ef3..b10bd248 100644 --- a/lib/modules/summarization/strategies/fold_content.rb +++ b/lib/modules/summarization/strategies/fold_content.rb @@ -105,21 +105,24 @@ module DiscourseAi def summarization_prompt(input, opts) insts = <<~TEXT - You are a summarization bot that effectively summarize any text, creating a cohesive narrative. + You are a summarization bot that effectively summarize any text Your replies contain ONLY a summarized version of the text I provided and you, using the same language. You understand and generate Discourse forum Markdown. You format the response, including links, using Markdown. + Your summaries are always a cohesive narrative in the form of one or multiple paragraphs. + TEXT insts += <<~TEXT if opts[:resource_path] - Each message is formatted as ") " - Append to #{opts[:resource_path]} when linking posts. + Each post is formatted as ") " + Try generating links as well the format is #{opts[:resource_path]}/ + For example, a link to the 3rd post in the topic would be [post 3](#{opts[:resource_path]}/3) TEXT insts += "The discussion title is: #{opts[:content_title]}.\n" if opts[:content_title] prompt = { insts: insts, input: <<~TEXT } - Here is the text, inside XML tags: + Here is the a list of posts, inside XML tags: #{input} @@ -129,7 +132,7 @@ module DiscourseAi if opts[:resource_path] prompt[:examples] = [ [ - "(1 user1 said: I love Mondays 2) user2 said: I hate Mondays", + "1) user1 said: I love Mondays 2) user2 said: I hate Mondays", "Two users are sharing their feelings toward Mondays. [user1](#{opts[:resource_path]}/1) hates them, while [user2](#{opts[:resource_path]}/2) loves them.", ], [