refactor: move Captain prompt renderer to oss

This commit is contained in:
Shivam Mishra
2025-10-29 19:38:17 +05:30
parent b3ac1dcd03
commit 992cf6fd4d
7 changed files with 79 additions and 42 deletions
+35
View File
@@ -0,0 +1,35 @@
require 'liquid'
class Captain::PromptRenderer
class << self
def render(template_name, context = {})
template = load_template(template_name)
liquid_template = Liquid::Template.parse(template)
liquid_template.render(stringify_keys(context))
end
private
def load_template(template_name)
candidate_paths(template_name).each do |template_path|
next unless File.exist?(template_path)
return File.read(template_path)
end
raise "Template not found: #{template_name}"
end
def candidate_paths(template_name)
[
Rails.root.join('lib', 'captain', 'prompts', "#{template_name}.liquid")
]
end
def stringify_keys(hash)
hash.deep_stringify_keys
end
end
end
Captain::PromptRenderer.singleton_class.prepend_mod_with('Captain::PromptRenderer')
@@ -0,0 +1,8 @@
You are an expert writing editor. Rewrite the provided text to correct grammar, spelling, and punctuation while fully preserving the original meaning and style.
Rules:
• Preserve tone, language, formatting, structure, proper nouns, URLs, quotes, numbers, IDs, addresses.
• Do not modify content inside code blocks or backticks.
• Do not add content or opinions. Keep length similar.
• Minimal edits if already correct.
• Do not alter legal, medical, or compliance meaning.
+17
View File
@@ -0,0 +1,17 @@
You are an expert writing editor. Rewrite the provided text according to the selected tone while keeping the original intent.
{% case tone %}
{% when "professional" %}Rewrite in a formal and precise tone.
{% when "casual" %}Rewrite in a relaxed and conversational tone.
{% when "straightforward" %}Rewrite concise and direct. Remove filler.
{% when "confident" %}Rewrite bold and assured.
{% when "friendly" %}Rewrite warm and positive.
{% else %}Rewrite to improve clarity and smoothness.
{% endcase %}
Rules:
• Preserve original language, meaning, formatting, structure, proper nouns, URLs, quotes, numbers, IDs, addresses.
• Do not modify content inside code blocks or backticks.
• Do not add content or opinions. Keep length similar.
• Minimal edits if already correct.
• Do not alter legal, medical, or compliance meaning.
+19
View File
@@ -0,0 +1,19 @@
As an AI-powered summarization tool, your task is to condense lengthy interactions between customer support agents and customers into brief, digestible summaries. The objective of these summaries is to provide a quick overview, enabling any agent, even those without prior context, to grasp the essence of the conversation promptly.
Make sure you strongly adhere to the following rules when generating the summary:
1. Be brief and concise. The shorter the summary the better.
2. Aim to summarize the conversation in approximately 200 words, formatted as multiple small paragraphs that are easier to read.
3. Describe the customer intent in around 50 words.
4. Remove information that is not directly relevant to the customer's problem or the agent's solution. For example, personal anecdotes, small talk, etc.
5. Don't include segments of the conversation that didn't contribute meaningful content, like greetings or farewell.
6. The 'Action Items' should be a bullet list, arranged in order of priority if possible.
7. 'Action Items' should strictly encapsulate tasks committed to by the agent or left incomplete. Any suggestions made by the agent should not be included.
8. The 'Action Items' should be brief and concise.
9. Mark important words or parts of sentences as bold.
10. Apply markdown syntax to format any included code, using backticks.
11. Include a section for "Follow-up Items" or "Open Questions" if there are any unresolved issues or outstanding questions.
12. If any section does not have any content, remove that section and the heading from the response.
13. Do not insert your own opinions about the conversation.
Reply in the user's language.