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

相关推荐
程序员佳佳3 小时前
【万字硬核】从零构建企业级AI中台:基于Vector Engine整合GPT-5.2、Sora2与Veo3的落地实践指南
人工智能·gpt·chatgpt·ai作画·aigc·api·ai编程
kaizq3 小时前
AI-MCP-SQLite-SSE本地服务及CherryStudio便捷应用
python·sqlite·llm·sse·mcp·cherry studio·fastmcp
亚里随笔7 小时前
GenEnv:让AI智能体像人一样在_游戏_中成长
人工智能·游戏·llm·rl·agentic
sinat_286945198 小时前
opencode
人工智能·算法·chatgpt
学历真的很重要8 小时前
LangChain V1.0 Context Engineering(上下文工程)详细指南
人工智能·后端·学习·语言模型·面试·职场和发展·langchain
工藤学编程9 小时前
零基础学AI大模型之LangChain智能体执行引擎AgentExecutor
人工智能·langchain
彼岸花开了吗9 小时前
构建AI智能体:八十、SVD知识整理与降维:从数据混沌到语义秩序的智能转换
人工智能·python·llm
栀秋66610 小时前
智能驱动的 Git 提交:基于 Ollama 大模型的规范化提交信息生成方案
react.js·llm·ollama
sinat_2869451912 小时前
AI Coding LSP
人工智能·算法·prompt·transformer
AI架构师易筋13 小时前
AIOps 告警归因中的提示工程:从能用到可上生产(4 阶梯)
开发语言·人工智能·llm·aiops·rag