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

相关推荐
CoderJia程序员甲2 小时前
GitHub 热榜项目 - 日榜(2025-12-19)
ai·开源·llm·github
huohuopro2 小时前
LangChain | LangGraph V1教程 #3 从路由器到ReAct架构
前端·react.js·langchain
沛沛老爹4 小时前
Web开发者快速上手AI Agent:基于LangChain的提示词应用优化实战
人工智能·python·langchain·提示词·rag·web转型
周末程序猿4 小时前
RAG实战|8种RAG架构浅析
langchain·aigc
骚戴5 小时前
n1n:从替代LiteLLM Proxy自建网关到企业级统一架构的进阶之路
人工智能·python·大模型·llm·gateway·api
rockingdingo8 小时前
0-1教程 ChatGPT Apps Store应用提交教程——和MCP开发部署
人工智能·chatgpt·chatgpt-app
春天的菠菜8 小时前
【LangChain第3章】LangChain使用之Chains
人工智能·langchain
长空任鸟飞_阿康10 小时前
LangChain 技术栈全解析:从模型编排到 RAG 实战
前端·python·langchain
沛沛老爹10 小时前
Web开发者进阶AI Agent:LangChain提示词模板与输出解析器实战
人工智能·ai·langchain·llm·agent·提示词·web转型
骚戴11 小时前
LLM API Gateway:LLM API 架构、AI 聚合与成本优化全解(2025深度指南)
人工智能·python·大模型·llm·gateway·api