Python使用OpenAI官方库调用ChatGPT转发API调用示例(新版+旧版)

闪电发卡2年前ChatGPT4971

新版:OpenAI库1.0.0以上

调用参数解释:https://www.chatgptzh.com/post/12.html


from openai import OpenAI

client = OpenAI(
    # 输入转发API Key,注意转发地址需要加/v1
    api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxx",
    base_url="https://api.wumingai.com/v1"   
)

completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "你是谁!"}
    ],
    stream=True  # 是否开启流式输出
)

# 非流式输出获取结果
# print(completion.choices[0].message)
# 流式输出获取结果
for chunk in completion:
    print(chunk.choices[0].delta)


旧版:


import openai

# 输入转发API Key,注意转发地址需要加/v1
openai.api_key = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
openai.api_base = "https://api.wumingai/v1"


response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",  
    messages="hello",
    max_tokens=2000,
    n=1,
    stop=None,
    temperature=0.5,
)

response_content = response.choices[0].message.content
print(response_content)


相关文章

ChatGPT注册使用教程,无需注册在线体验chatgpt方式

ChatGPT注册使用教程,无需注册在线体验chatgpt方式

最近大火的ChatGPT,获得微软巨额投资,连比尔·盖茨都盛赞:“AI将成为2023年最热门的话题,那是合适的。不少商界大佬也纷纷夸赞ChatGPT。 马斯克表示,“ChatGPT很惊人,我们离强大到...

如何选择最佳GPT-5会员代充方案

闪电发卡ChatGPT和Claude产品推荐: ChatGPT Pro共享账号 ChatGPT Pro独享账号 ChatGPT独享账号 Claude Pr...

解密Prompt系列:升级Instruction Tuning:Flan/T0/InstructGPT/TKInstruct

解密Prompt系列:升级Instruction Tuning:Flan/T0/InstructGPT/TKInstruct

这一章我们聊聊指令微调,哈哈只要你细品,你就会发现大家对prompt和instruction的定义存在些出入,部分认为instruction是prompt的子集,部分认为instruction是句子类...

OpenAI API Key购买批发5美元余额,ChatGPT模型GPT3.5、GPT4.0直连APIKey和转发APIKey购买批发代充值,可自定义余额,安全稳定不限速

一、什么是OpenAI APIKey?OpenAI APIKey是OpenAI旗下产品ChatGPT、Dall-E 3、Sora等调用其接口服务所必须得密钥,可以验证调用权限,是一个形如sk-xxxx...

购买ChatGPT Plus账号的优势:详细分析和操作步骤

闪电发卡ChatGPT产品推荐:ChatGPT独享账号:https://www.chatgptzh.com/post/86.htmlChatGPT Plus独享共享账号购买代充:https://www...

ChatGPT Plus 4.0和GPT-4o、4o mini、o1、o3等模型的区别和联系

闪电发卡ChatGPT产品推荐: ChatGPT独享账号 ChatGPT Plus 4.0独享共享账号购买代充 ChatGPT APIKey 3.5和4.0购买充值(直连+...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。