본문 바로가기
카테고리 없음

openai api key 이용방법

by pulluper 2024. 5. 15.
반응형

안녕하세요 pulluper 입니다. 

 

import openai 

openai.api_key = "API KEY"

response = openai.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
        {"role": "user", "content": "Where was it played?"}
    ]
)
# print(response['choices'][0]['message']['content'])
print(response.choices[0].message.content)

 

반응형

댓글