Giai đoạn | Mô tả |
---|---|
User Input | Câu hỏi, dữ liệu từ người dùng |
Conversational AI | AI tạo nội dung có cấu trúc từ câu hỏi |
Structured JSON PRD | Nội dung tài liệu tổ chức theo định dạng JSON |
Output Generators | Các module chuyển JSON sang các định dạng file khác nhau |
Export & Delivery | Giao tài liệu cho người dùng |
ruby-openai
cho phép tích hợp API OpenAI dễ dàng:require 'caracal'
class DocxGenerator def initialize(prd_json) @prd_json = prd_json end
def generate_docx(output_path) Caracal::Document.save(output_path) do |docx| docx.h1 @prd_json['title'] @prd_json['sections'].each do |section| docx.h2 section['heading'] docx.p section['content'] end end endend
class MarkdownGenerator TEMPLATE = <<~MD # <%= @prd_json['title'] %>
<% @prd_json['sections'].each do |section| %> ## <%= section['heading'] %>
<%= section['content'] %>
<% end %> MD
def initialize(prd_json) @prd_json = prd_json end
def generate_markdown ERB.new(TEMPLATE).result(binding) endend
require 'yaml'
class YamlGenerator def initialize(prd_json) @prd_json = prd_json end
def generate_yaml(output_path) File.write(output_path, @prd_json.to_yaml) endend
require 'odf-report'
class OdtGenerator def initialize(prd_json) @prd_json = prd_json end
def generate_odt(output_path) report = ODFReport::Report.new("template.odt") do |r| r.add_field("TITLE", @prd_json['title']) @prd_json['sections'].each_with_index do |section, index| r.add_field("HEADING#{index+1}", section['heading']) r.add_field("CONTENT#{index+1}", section['content']) end end report.generate(output_path) endend
require 'prawn'
class PdfGenerator def initialize(prd_json) @prd_json = prd_json end
def generate_pdf(output_path) Prawn::Document.generate(output_path) do |pdf| pdf.text @prd_json['title'], size: 24, style: :bold @prd_json['sections'].each do |section| pdf.move_down 10 pdf.text section['heading'], size: 18, style: :bold pdf.text section['content'], size: 12 end end endend
class TxtGenerator def initialize(prd_json) @prd_json = prd_json end
def generate_txt(output_path) content = [] content << @prd_json['title'] @prd_json['sections'].each do |section| content << "\n#{section['heading']}\n" content << "#{section['content']}\n" end File.write(output_path, content.join("\n")) endend