-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
149 lines (128 loc) · 4.5 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import openai from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
let apiKey = "";
let transcript = "";
let ai = null;
function getTranscriptSummaryAndActionItems(rawTranscript) {
return new Promise(async (resolve, reject) => {
try {
let cTranscript = await cleanTranscript(rawTranscript);
let summary = await abstractSummaryExtraction(cTranscript);
let actionItems = await actionItemExtraction(cTranscript);
resolve({ summary, actionItems });
} catch (error) {
console.log(error);
reject(error);
}
});
}
function abstractSummaryExtraction(transcription) {
return new Promise(async (resolve, reject) => {
try {
let response = await ai.chat.completions.create({
model: "gpt-3.5-turbo",
temperature: 0,
messages: [
{
role: "system",
content:
"You are a highly skilled AI trained in language comprehension and summarization. I would like you to read the following text and summarize it into a concise abstract paragraph. Aim to retain the most important points, providing a coherent and readable summary that could help a person understand the main points of the discussion without needing to read the entire text. Please avoid unnecessary details or tangential points.",
},
{
role: "user",
content: transcription,
},
],
});
resolve(response["choices"][0]["message"]["content"]);
} catch (error) {
reject(error);
}
});
}
function actionItemExtraction(transcription) {
return new Promise(async (resolve, reject) => {
try {
let response = await ai.chat.completions.create({
model: "gpt-3.5-turbo",
temperature: 0,
messages: [
{
role: "system",
content:
"You are an AI expert in analyzing conversations and extracting action items. Please review the text and identify any tasks, assignments, or actions that were agreed upon or mentioned as needing to be done. These could be tasks assigned to specific individuals, or general actions that the group has decided to take. Please list these action items clearly and concisely.",
},
{
role: "user",
content: transcription,
},
],
});
resolve(response["choices"][0]["message"]["content"]);
} catch (error) {
reject(error);
}
});
}
function cleanTranscript(transcript) {
return new Promise(async (resolve, reject) => {
try {
let lines = "";
let splitLines = transcript.split("\n");
for (var i = 0; i < splitLines.length; i++) {
let line = splitLines[i];
if (
line !== "WEBVTT" &&
line !== "" &&
!line.match(/^\d+$/) &&
!line.match(/^[0-9:.]{12} --> [0-9:.]{12}/)
) {
lines += line + "\n";
}
}
resolve(lines);
} catch (error) {
reject(error);
}
});
}
function reset() {
document.querySelector("#accordion-summary-content").innerHTML = "";
document.querySelector("#accordion-ai-content").innerHTML = "";
document.querySelector(".accordion").classList.add("d-none");
}
async function main() {
document.querySelector("input#apiKey").addEventListener("change", (e) => {
if (e.target.value === "") return;
apiKey = e.target.value;
});
document
.querySelector("textarea#transcript")
.addEventListener("change", (e) => {
if (e.target.value === "") return;
transcript = e.target.value;
});
document
.querySelector("button#generateSummary")
.addEventListener("click", async () => {
reset();
if (apiKey === "" || transcript === "") {
alert("Please enter your API key and transcript");
return;
}
document.querySelector("#spinner-container").classList.remove("d-none");
document.querySelector("button#generateSummary").disabled = true;
ai = new openai({
apiKey,
dangerouslyAllowBrowser: true,
});
let output = await getTranscriptSummaryAndActionItems(transcript);
document.querySelector("#accordion-summary-content").innerHTML =
output.summary;
document.querySelector("#accordion-ai-content").innerHTML =
output.actionItems;
document.querySelector("#spinner-container").classList.add("d-none");
document.querySelector(".accordion").classList.remove("d-none");
document.querySelector("button#generateSummary").disabled = false;
});
}
main();