1. OpenAi 사이트 접속
2. 회원가입 및 로그인 후 마이페이지 이동
https://platform.openai.com/account/org-settings
3. API 정보 확인
Settings -> Organization ID 확인
API keys -> Create new secret key 버튼 클릭 후 API 키 발급 -> KEY 확인
4. 코드 작성
const { Configuration, OpenAIApi } = require('openai');
const config = new Configuration({
apiKey: '*******',
organization: '*******'
});
const openai = new OpenAIApi(config);
const form = {
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: '질문할 내용 작성' }],
};
openai.createChatCompletion(form).then(({ data }) => {
let answerList = data?.choices ?? [];
if (!answerList.length) return '답변 없음';
let answer = answerList[0]?.message?.content ?? '';
let result = `답변: ${answer}`;
return result;
});