openai_api和doc文档的实验笔记和内容解读

相关资料

doc官方文档
大多数的内容都可以从官方文档的搜索当中找到
https://platform.openai.com/docs/overview
api-reference链接地址:
api调用的问题,以及一些旧版的api的内容,可以在api 应用程序接口 中找到
https://platform.openai.com/docs/api-reference/introduction

api reference

经典的版本使用错误

错误原因:openai.ChatCompletion.create(proj:MAD)

import openai
try:
    if self.model_name in support_models:
        response = openai.ChatCompletion.create(
            model=self.model_name,
            messages=messages,
            temperature=temperature,
            max_tokens=max_tokens,
            api_key=api_key,
        )
        gen = response['choices'][0]['message']['content']
    return gen

You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.

You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface.

Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28

A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742

最新的调用代码应该参考官网为https://platform.openai.com/docs/api-reference/streaming [proj:LVSR]

from openai import OpenAI
client = OpenAI(api_key=args.api_key_token)

stream = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Say this is a test"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

endpoints

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五阿哥爱跳舞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值