最近大家有没有发现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."},