最近大家有沒有發現Openai的openai
已經更新到1.6.1了,而且API的調用方式發生了巨大的變化,下面來看看openai
新的調用方式吧。
歡迎關注公眾號
module ‘openai’ has no attribute 'ChatCompletion. 提示
openai
的版本過低。(pip install -U openai
)
1. Chat API
from openai import OpenAI
api_key = ''
client = OpenAI(api_key=api_key)response = client.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."},