abstract logic into separate method
This commit is contained in:
parent
8ce7331870
commit
20701cb48a
|
@ -32,20 +32,26 @@ module DiscourseAi
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def summary_prompt(topic_id:, persona_id:, default_prompt:)
|
||||||
|
prompt_text = default_prompt
|
||||||
|
if persona_id
|
||||||
|
persona = AiPersona.find_by(id: persona_id)
|
||||||
|
prompt_text = persona.system_prompt if persona
|
||||||
|
end
|
||||||
|
DiscourseAi::Completions::Prompt.new(prompt_text, topic_id: topic_id)
|
||||||
|
end
|
||||||
|
|
||||||
def summary_extension_prompt(summary, contents)
|
def summary_extension_prompt(summary, contents)
|
||||||
resource_path = "#{Discourse.base_path}/t/-/#{target.id}"
|
resource_path = "#{Discourse.base_path}/t/-/#{target.id}"
|
||||||
content_title = target.title
|
content_title = target.title
|
||||||
input =
|
input =
|
||||||
contents.map { |item| "(#{item[:id]} #{item[:poster]} said: #{item[:text]})" }.join
|
contents.map { |item| "(#{item[:id]} #{item[:poster]} said: #{item[:text]})" }.join
|
||||||
|
|
||||||
if SiteSetting.ai_summary_consolidator_persona_id
|
|
||||||
prompt =
|
prompt =
|
||||||
DiscourseAi::Completions::Prompt.new(
|
summary_prompt(
|
||||||
AiPersona.find_by(id: SiteSetting.ai_summary_consolidator_persona_id).system_prompt,
|
|
||||||
topic_id: target.id,
|
topic_id: target.id,
|
||||||
)
|
persona_id: SiteSetting.ai_summary_consolidator_persona_id,
|
||||||
else
|
default_prompt: <<~TEXT,
|
||||||
prompt = DiscourseAi::Completions::Prompt.new(<<~TEXT, topic_id: target.id) # summary extension prompt
|
|
||||||
You are an advanced summarization bot tasked with enhancing an existing summary by incorporating additional posts.
|
You are an advanced summarization bot tasked with enhancing an existing summary by incorporating additional posts.
|
||||||
|
|
||||||
### Guidelines:
|
### Guidelines:
|
||||||
|
@ -60,7 +66,7 @@ module DiscourseAi
|
||||||
- Example: link to the 13th post by joe: [joe](#{resource_path}/13)
|
- Example: link to the 13th post by joe: [joe](#{resource_path}/13)
|
||||||
- When formatting usernames either use @USERNAME or [USERNAME](#{resource_path}/POST_NUMBER)
|
- When formatting usernames either use @USERNAME or [USERNAME](#{resource_path}/POST_NUMBER)
|
||||||
TEXT
|
TEXT
|
||||||
end
|
)
|
||||||
|
|
||||||
prompt.push(type: :user, content: <<~TEXT.strip)
|
prompt.push(type: :user, content: <<~TEXT.strip)
|
||||||
### Context:
|
### Context:
|
||||||
|
@ -89,14 +95,11 @@ module DiscourseAi
|
||||||
input =
|
input =
|
||||||
contents.map { |item| "(#{item[:id]} #{item[:poster]} said: #{item[:text]} " }.join
|
contents.map { |item| "(#{item[:id]} #{item[:poster]} said: #{item[:text]} " }.join
|
||||||
|
|
||||||
if SiteSetting.ai_summary_persona_id.present?
|
|
||||||
prompt =
|
prompt =
|
||||||
DiscourseAi::Completions::Prompt.new(
|
summary_prompt(
|
||||||
AiPersona.find_by(id: SiteSetting.ai_summary_consolidator_persona_id).system_prompt,
|
|
||||||
topic_id: target.id,
|
topic_id: target.id,
|
||||||
)
|
persona_id: SiteSetting.ai_summary_persona_id,
|
||||||
else
|
default_prompt: <<~TEXT,
|
||||||
prompt = DiscourseAi::Completions::Prompt.new(<<~TEXT.strip, topic_id: target.id)
|
|
||||||
You are an advanced summarization bot that generates concise, coherent summaries of provided text.
|
You are an advanced summarization bot that generates concise, coherent summaries of provided text.
|
||||||
|
|
||||||
- Only include the summary, without any additional commentary.
|
- Only include the summary, without any additional commentary.
|
||||||
|
@ -110,7 +113,7 @@ module DiscourseAi
|
||||||
- Example: link to the 13th post by joe: [joe](#{resource_path}/13)
|
- Example: link to the 13th post by joe: [joe](#{resource_path}/13)
|
||||||
- When formatting usernames either use @USERNMAE OR [USERNAME](#{resource_path}/POST_NUMBER)
|
- When formatting usernames either use @USERNMAE OR [USERNAME](#{resource_path}/POST_NUMBER)
|
||||||
TEXT
|
TEXT
|
||||||
end
|
)
|
||||||
|
|
||||||
prompt.push(
|
prompt.push(
|
||||||
type: :user,
|
type: :user,
|
||||||
|
|
Loading…
Reference in New Issue