Skip to content

Commit

Permalink
refactor letter api (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdavis committed Jun 5, 2024
1 parent 9beac71 commit 9bd1a67
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions apps/registry/pages/api/letter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ const { createClient } = require('@supabase/supabase-js');
const supabaseUrl = 'https://itxuhvvwryeuzuyihpkp.supabase.co';
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);
/*
#todo
- add an input box to post the job description
- save JD in local storage
- buttons that can change tone of the letter
- save settings in local storage

/*
#wishlist
- google the company, and include as much up to date information as possible in the prompt
- Google the company, and include as much up to date information as possible in the prompt
*/

export default async function handler(req, res) {
const { username, jobDescription, tone } = req.body;

// pull from the cache
const { data } = await supabase
.from('resumes')
.select()
Expand All @@ -31,7 +23,7 @@ export default async function handler(req, res) {

const resumeString = JSON.stringify(resume);

const api = new ChatGPTAPI({
const gpt = new ChatGPTAPI({
apiKey: process.env.OPENAI_API_KEY,
model: 'gpt-4o',
completionParams: {
Expand All @@ -41,9 +33,9 @@ export default async function handler(req, res) {

let prompt = [
`
You are a human candidate for a job. Read the supplied resume and pretend you are that person. Your resume has been supplied to them.
You are a human candidate for a job. Read the supplied resume and pretend you are that person. Your resume has been supplied to them.
This is your resume in the JSON format. Reference it for the cover letter.
This is your resume in the JSON format. Reference it for the cover letter.
${resumeString}
Expand All @@ -52,24 +44,18 @@ This is your resume in the JSON format. Reference it for the cover letter.

if (jobDescription) {
prompt.push(`
Here is the job description I am applying for;
${jobDescription}.
`);
}

prompt.push(
`Using a ${tone} tonality. Format your response using Markdown. Don't be afraid to name your lack of experience the candidate might have but focus on your strengths. Keep it two a couple short paragraphs only 300 words.`
);
`Using a ${tone} tonality. Format your response using Markdown. Don't be afraid to name your lack of experience the candidate might have but focus on your strengths. Keep it two a couple short paragraphs only 300 words.
prompt.push(
'Please write a short cover letter. Make sure you write a cover letter.'
Please write a short cover letter. Make sure you write a cover letter.`
);

console.log({ prompt });

const res2 = await api.sendMessage(prompt.join(''));
const gptRes = await gpt.sendMessage(prompt.join(''));

return res.status(200).send(res2.text);
return res.status(200).send(gptRes.text);
}

0 comments on commit 9bd1a67

Please sign in to comment.