Thành phần | Mô tả |
---|---|
Đầu vào người dùng | Câu hỏi, dữ liệu hội thoại, file đính kèm |
AI hội thoại (OpenAI API) | Sinh nội dung PRD có cấu trúc JSON |
Bộ sinh tài liệu | Định dạng tài liệu đầu ra (DOCX, PPTX, Markdown, YAML, ODT, PDF, TXT) |
Phân phối | Xuất file đến người dùng, ví dụ qua email hoặc cập nhật lên hệ thố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