Openai的openai新版本调用方式

2023-12-24 23:45:27

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

文章来源:https://blog.csdn.net/weixin_48030475/article/details/135188311
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。