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

闪电发卡2年前ChatGPT5442

新版: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)


相关文章

【2025最新指南】ChatGPT Plus 4o账号购买渠道对比与价格分析

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

GPT-o1与GPT-4比较:值不值得升级购买的深度分析

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

GPT-4o背后的秘密:深入了解它的运作方式

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

什么是通用人工智能AGI?为什么要实现通用人工智能? 以及实现通用人工智能的方法

当你开始积极探索未来科技的时候,你已经是大部分人的英雄了----闪电发卡关于AGI的一些思考1、什么是通用人工智能?通用人工智能( Artificial General Intelligence),也...

反击ChatGPT,谷歌正式推出Bard!结果...

反击ChatGPT,谷歌正式推出Bard!结果...

1、谷歌发大招这段时间,一直在看大神相互打架。OpenAI 宣布发布 GPT-4,百度发布了文心一言,微软深夜放了一个炸弹发布 Copilot。紧接着到昨天晚上,谷歌终于发大招发布了 Bar...

深入解析ChatGPT原理:人工智能聊天机器人的核心技术

大家好,欢迎来到我的博客!今天我们要聊聊一个非常热门的话题——ChatGPT。相信大家对这个词并不陌生,它是OpenAI推出的一个强大的聊天机器人,已经在多个领域展现了非凡的能力。那么ChatGPT究...