카테고리 없음

OpenAI API(GPT) JSON으로 응답 받기

순코딩 2025. 3. 29. 10:39
  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 형식 응답 강제
  });