더북(TheBook)

ch01_test_openai.py

import os
from openai import OpenAI

client = OpenAI(
    # 발급받은 API Key 입력
    api_key = "sk-proj-xHoXnvJdtdzJPmFFGcWqaE2Yq4vWbBAoXCfhHYEnkREWx…" --- ➊
)

chat_completion = client.chat.completions.create(
    messages = [
        {
            "role": "user",
            "content": "Say this is a test.",
        }
    ],
    model = "gpt-4o",
)
print(chat_completion.choices[0].message.content) --- ➋
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.