Skip to content

Commit

Permalink
chore: update to gpt 3.5 turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
novellac committed Mar 20, 2023
1 parent 5f78f15 commit cf4472a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
24 changes: 18 additions & 6 deletions api/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ const handler = async (req) => {
const { bio, jobDescription } = await req.json()

const prompt = `
Given the current resume profile, ${bio}, generate an improved resume
profile based on the job description,
${jobDescription}. If the resume profile mentions fewer years of experience than the
job description asks for, then only use the number of years of experience from the resume profile.
Given the current resume profile, ${bio},
generate an improved resume profile based
on the job description, ${jobDescription}.
If the resume profile mentions fewer years
of experience than the job description asks
for, then only use the number of years of
experience from the resume profile and do not
mention the number of years of experience from
the job description.
`

if (!bio || !jobDescription) {
return new Response(
'No resume profile or no job description in the request',
{ status: 400 }
)
}

const payload = {
model: 'text-davinci-003',
prompt,
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: prompt }],
temperature: 0.7,
top_p: 1,
frequency_penalty: 0,
Expand Down
5 changes: 3 additions & 2 deletions utils/OpenAIStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function OpenAIStream(payload) {

let counter = 0

const res = await fetch('https://api.openai.com/v1/completions', {
const res = await fetch('https://api.openai.com/v1/chat/completions', {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.OPENAI_API_KEY ?? ''}`,
Expand All @@ -27,11 +27,12 @@ export async function OpenAIStream(payload) {
}
try {
const json = JSON.parse(data)
const text = json.choices[0].text
const text = json.choices[0].delta?.content || ''
if (counter < 2 && (text.match(/\n/) || []).length) {
return
}
const queue = encoder.encode(text)

controller.enqueue(queue)
counter++
} catch (e) {
Expand Down

1 comment on commit cf4472a

@vercel
Copy link

@vercel vercel bot commented on cf4472a Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.