Skip to content

Commit

Permalink
UPDATE : updated ChatGPT API Call
Browse files Browse the repository at this point in the history
  • Loading branch information
judemin committed Jan 30, 2024
1 parent ef6c365 commit 82a1452
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions processNLText.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,36 @@ const openai = new OpenAI({

async function callGPTApi(keyword) {
const prompt =
`λŒ€ν•œλ―Όκ΅­ λŒ€ν•™κ΅ κ°•μ˜μ—μ„œ ${keyword}의 μ˜λ―Έμ™€ ` +
`학생듀을 ν•™μŠ΅μ„ 도와쀄 수 μžˆλŠ” λΆ€κ°€ 정보에 λŒ€ν•΄ 128자 μ΄λ‚΄λ‘œ λ‹΅λ³€ν•΄μ€˜`;

const chatCompletion = await openai.chat.completions.create({
messages: [{ role: 'user', content: prompt }],
model: 'gpt-3.5-turbo-1106',
});

return chatCompletion.data.choices[0].text.trim();
`λŒ€ν•œλ―Όκ΅­ λŒ€ν•™κ΅ κ°•μ˜μ—μ„œ ${keyword}의 사전적 의미λ₯Ό 128자 μ΄λ‚΄λ‘œ λ‹΅λ³€ν•΄μ€˜`;

try {
const chatCompletion = await openai.chat.completions.create({
messages: [{ role: 'user', content: prompt }],
model: 'gpt-3.5-turbo',
});

console.log(chatCompletion.choices[0].message);
if (chatCompletion && chatCompletion.choices) {
return chatCompletion.choices[0].message.content;
} else {
console.error('Invalid response structure:', chatCompletion);
return 'Error: Invalid response structure';
}
} catch (error) {
console.error('Error in API call:', error);
return `Error: ${error.message}`;
}
}

function processNLText(clientSocket, textData) {
return new Promise(async (resolve, reject) => {
try {
console.log(callGPTApi("κ΄€μ„±"));
const response = await axios.post(
process.env.FLASK_HOST + '/process',
textData,
{ headers: { 'Content-Type': 'application/json' } }
);


const nlpResponse = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
const unProcessedText = nlpResponse.unProcessedText;

Expand Down

0 comments on commit 82a1452

Please sign in to comment.