-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreview.js
More file actions
76 lines (70 loc) · 2.87 KB
/
review.js
File metadata and controls
76 lines (70 loc) · 2.87 KB
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
function convertPDFtoText(pdfFile, callback) {
const fileReader = new FileReader();
fileReader.readAsArrayBuffer(pdfFile);
fileReader.onload = () => {
const typedArray = new Uint8Array(fileReader.result);
pdfjsLib.getDocument(typedArray).promise.then((pdfDoc) => {
let pages = Array.from({ length: pdfDoc.numPages }, (_, i) => i + 1);
return Promise.all(pages.map((pageNum) => pdfDoc.getPage(pageNum)));
})
.then((pages) => {
return Promise.all(
pages.map((page) => {
return page.getTextContent();
})
);
})
.then((contents) => {
let textContent = '';
contents.forEach((content) => {
content.items.forEach((item) => {
textContent += item.str + ' ';
});
});
callback(textContent);
})
.catch((error) => {
console.error(error);
});
};
}
const apiKey= "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";// TODO: Add your key
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: apiKey,
});
const openai = new OpenAIApi(configuration);
const myElement = document.getElementById('resume-review');
fetch('Resumes/file_info.json')
.then(response => response.json())
.then(data => {
const path = `Resumes/${data.name}`;
fetch(path) // fetch the PDF file from the server
.then(response => response.blob())
.then(pdfBlob => {
convertPDFtoText(pdfBlob, async (text) => {
console.log(text);
const message = [{
role: "system", content: `You are a college admissions officer. Do not include information about being an AI.
You are to review the resume provided from an admissions standpoint.`
}, {
role: "user", content: `Please give feedback on my resume along with
other skills I can work on: '${text}'`
}];
// Make a request to the OpenAI API
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: message,
temperature: 0.2,
max_tokens: 2000,
n: 1
});
const messageOutput = completion?.data?.choices?.[0]?.message?.content;
console.log(messageOutput);
myElement.textContent = messageOutput;
});
})
.catch((error) => {
console.error(error);
});
});