코드
import OpenAI from "openai";
// OpenAI 클라이언트 초기화
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// OpenAI API 호출
const completion = await openai.chat.completions.create({
model: "gpt-4o", // 사용할 AI 모델 지정
messages: [
// 시스템 메시지로 AI의 역할과 응답 형식 정의
{ role: "system", content: systemPrompt },
// 사용자 메시지로 케이스 정보 전달
{ role: "user", content: userPrompt },
],
temperature: 0.7, // 응답의 창의성 조절 (0: 결정적, 1: 창의적)
response_format: { type: "json_object" }, // JSON 형식 응답 강제
});
// AI 응답 추출
const aiResponse = completion.choices[0].message.content;
'라이브러리' 카테고리의 다른 글
[Firebase] FCM을 활용한 웹 푸쉬 알림 구현방법 A to Z (1) | 2025.04.01 |
---|---|
[react-swiper] 스와이퍼 범위가 무한히 늘어나는 버그 | 스크롤바가 무한히 늘어나는 원인 및 해결방법 (0) | 2025.02.23 |
[styled-components] Next.js 15 + styled-components 전역 스타일 설정 방법 | 테마 설정 방법 | 테마, (0) | 2025.02.12 |
[react-dnd] 드래그앤드랍 시 최신 state를 가져오지 못하는 버그 (0) | 2025.02.09 |
[Swiper] 리액트 스와이퍼 자동 재생 특정 횟수에서 멈추기 (0) | 2025.01.14 |