Class: SummarizeMeeting::Meeting
- Inherits:
-
Object
- Object
- SummarizeMeeting::Meeting
- Defined in:
- lib/summarize-meeting/meeting.rb
Constant Summary collapse
- RESPONSE_RESERVE_TOKENS =
1000- LINE_SUMMARY_PROMPT_TEMPLATE =
[ { role: "system", content: "You are an assistant summarizing a meeting.", }, { role: "system", content: "The transcript of the meeting is split into {{chunkCount}} chunks. This is the chunk number {{chunkIndex}} of {{chunkCount}}.", }, { role: "assistant", content: "Please provide me with the next chunk of the transcript.", }, { role: "user", content: "{{chunk}}", } ]
- CONSOLIDATED_SUMMARY_PROMPT_TEMPLATE =
[ { role: "system", content: "You are an assistant summarizing a meeting.", }, { role: "system", content: "Notes about the meeting have been compiled.", }, { role: "system", content: " Your job is to write a thorough summary of the meeting.\n The summary should start with a brief overview of the meeting.\n The summary should be detailed and should extract any action items that were discussed.\n The summary should be organized into sections with headings and bullet points.\n The summary should include a list of attendees.\n The order of the sections should be overview, attendees, action items, and detailed notes by topic.\n Write the summary in markdown format.\n CONTENT\n },\n {\n role: \"assistant\",\n content: \"Please provide me with notes from the meeting.\",\n },\n {\n role: \"user\",\n content: \"{{notes}}\",\n }\n]\n"
Instance Attribute Summary collapse
-
#transcript ⇒ Object
readonly
Returns the value of attribute transcript.
Instance Method Summary collapse
-
#initialize(transcript) ⇒ Meeting
constructor
A new instance of Meeting.
- #split_lines_into_equal_size_chunks(lines, max_chunk_word_count) ⇒ Object
- #summarize ⇒ Object
- #summarize_chunk(chunk, chunk_index, chunk_count, previous_chunks_summary) ⇒ Object
Constructor Details
#initialize(transcript) ⇒ Meeting
Returns a new instance of Meeting.
59 60 61 |
# File 'lib/summarize-meeting/meeting.rb', line 59 def initialize(transcript) @transcript = transcript end |
Instance Attribute Details
#transcript ⇒ Object (readonly)
Returns the value of attribute transcript.
63 64 65 |
# File 'lib/summarize-meeting/meeting.rb', line 63 def transcript @transcript end |
Instance Method Details
#split_lines_into_equal_size_chunks(lines, max_chunk_word_count) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/summarize-meeting/meeting.rb', line 99 def split_lines_into_equal_size_chunks(lines, max_chunk_word_count) chunks = [] chunk = [] chunk_word_count = 0 lines.each do |line| line_word_count = line.split.size if chunk_word_count + line_word_count > max_chunk_word_count chunks << chunk chunk = [] chunk_word_count = 0 end chunk << line chunk_word_count += line_word_count end chunks << chunk chunks end |
#summarize ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/summarize-meeting/meeting.rb', line 65 def summarize # Step 1. Split the transcript into lines. lines = transcript.lines # Step 2. Calculate the maximum chunk size in words. template_word_count = LINE_SUMMARY_PROMPT_TEMPLATE.map { |line| line[:content].split.size }.sum template_token_count = SummarizeMeeting::Ai.calculate_word_token_count(template_word_count) max_chunk_token_count = SummarizeMeeting::Ai::MAX_TOTAL_TOKENS - RESPONSE_RESERVE_TOKENS - template_token_count max_chunk_word_count = SummarizeMeeting::Ai.calculate_token_word_count(max_chunk_token_count) # Step 3. Split the transcript into equally sized chunks. chunks = split_lines_into_equal_size_chunks(lines, max_chunk_word_count) # Step 4. Summarize each chunk. previous_chunks_summary = "" chunks.each_with_index do |chunk, chunk_index| chunk_summary = summarize_chunk(chunk, chunk_index, chunks.size, previous_chunks_summary) previous_chunks_summary += chunk_summary end # Step 5. Write a consolidated summary. consolidated_template = CONSOLIDATED_SUMMARY_PROMPT_TEMPLATE prompt = Mustache.render(consolidated_template.to_json, { notes: previous_chunks_summary.to_json }) = JSON.parse(prompt) SummarizeMeeting::Ai.chat() end |
#summarize_chunk(chunk, chunk_index, chunk_count, previous_chunks_summary) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/summarize-meeting/meeting.rb', line 92 def summarize_chunk(chunk, chunk_index, chunk_count, previous_chunks_summary) template = LINE_SUMMARY_PROMPT_TEMPLATE prompt = Mustache.render(template.to_json, { chunkCount: chunk_count, chunkIndex: chunk_index + 1, chunk: chunk.join("\n").to_json }) = JSON.parse(prompt) SummarizeMeeting::Ai.chat() end |