Langchain访问OpenAI ChatGPT API Account deactivated的另类方法,访问跳板机API

笔者曾经写过 ChatGPT OpenAI API请求限制 尝试解决

Account deactivated. Please contact us through our help center at help.openai.com if you need assistance.

结果如何? 没有啥用。目前发现一条曲线救国的方案。

1. 在官方 openai 库中使用

此处为最新OpenAI包调用方式

python 复制代码
from openai import OpenAI

client = OpenAI(
    # #将这里换成你在orisound api keys拿到的密钥
    api_key="sk-xxx",
    # 这里将官方的接口访问地址,替换成orisound的入口地址
    base_url="https://orisound.cn/v1"
)

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Say this is a test",
        }
    ],
    model="gpt-3.5-turbo",
)

print(chat_completion)

2. 在 LangChain 中使用

注意:openai_api_base 的末尾要加上 /v1,

python 复制代码
from langchain.chat_models import ChatOpenAI

llm = ChatOpenAI(
    openai_api_base="https://aihubmix.com/v1", # 注意,末尾要加 /v1
    openai_api_key="sk-3133f******fee269b71d",
)

res = llm.predict("hello")

print(res)

示例代码,使用LLM进行预测

核心其实在于key和url的设置

方法有:

  1. 使用环境变量来设置
  2. 使用变量来传入
  3. 使用手动设置环境变量
python 复制代码
import os
import requests
import time
import json
import time
from langchain.llms import OpenAI

API_SECRET_KEY = "你在aihubmix的key";
BASE_URL = "https://aihubmix.com/v1"; #aihubmix的base-url

os.environ["OPENAI_API_KEY"] = API_SECRET_KEY
os.environ["OPENAI_API_BASE"] = BASE_URL

def text():
    llm = OpenAI(temperature=0.9)
    text = "What would be a good company name for a company that makes colorful socks?"
    print(llm(text))

if __name__ == '__main__':
    text();

运行后可以看到返回:

python 复制代码
Lively Socks.

参考

https://aihubmix.com/about

相关推荐
孤狼GPT8 分钟前
ChatGPT、Codex实战:为什么AI一次改太多代码,反而更容易出问题?
chatgpt·codex·ai agent·chatgpt plus·chatgpt pro·ai coding
swipe1 小时前
RabbitMQ 实战:AI Agent 里异步处理的标配方案(手把手 + 4 种交换机全解析)
后端·面试·langchain
tachibana21 小时前
性能指标的口径选择
数据库·人工智能·架构·大模型·llm
闲研随记2 小时前
【文献阅读 ICLR 2026】RL算法:DECS
算法·llm·强化学习·iclr·rl
l1258653 小时前
# RAG上线评估指标体系:六大核心指标与压测实战全解析
数据库·人工智能·python·mysql·langchain·milvus
知几蜗牛4 小时前
0 后端 · 0 数据库 · 0 备案:用 AI 两天搓出的股票管理系统,开源了
前端·后端·llm
不灭的程序员阿澄4 小时前
把多个 AI 网站装进一个常驻托盘的桌面窗口里,像切换原生 App 一样切换 AI
人工智能·chatgpt
精彩AI说5 小时前
ChatGPT生成的内容太长怎么办?控制字数、精简回答与输出长度设置方法
chatgpt·ai写作·提示词·ai工具·chatgpt教程·内容精简
CoderJia程序员甲6 小时前
GitHub 热榜项目 - 周榜(2026-08-22)
ai·大模型·llm·github·ai教程
Linguwen6 小时前
中山GEO分享会回顾文
人工智能·chatgpt