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

闪电发卡2年前ChatGPT4835

新版: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 Plus以使用GPT-5的增强功能

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

查询OpenAI账号APIKey可用余额、使用量和使用明细接口,用python实现

现在可以使用以下接口进行实现Pythonapikey = ""     subscription_url =...

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

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

一步到位:如何轻松预约和购买ChatGPT Plus 5会员

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

ChatGPT 3.5 vs 4.0:API Key购买指南及使用差异分析

闪电发卡快捷直达购买链接:ChatGPT 3.5 API(5美元,直连):https://www.shandianfk.com/buy/24ChatGPT 3.5 API(5美元,转发):https:...

ChatGPT和OpenAI国内保姆级登录改密使用问题解决图文教程,带账号使用常见问题解决方案

ChatGPT和OpenAI国内保姆级登录改密使用问题解决图文教程,带账号使用常见问题解决方案

按顺序仔细做,解决99%问题剩下1%的问题请附上 查IP和显示错误的截图问客服。PS:由于法律问题,T子问题自行解决,请不要来问有没有推荐、怎么开全局什么的,谢谢配合。没有账号的可以点击获取:http...

发表评论    

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