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

相关推荐
索西引擎8 分钟前
【langchain 1.0】ChromaDB 原生 API 实战:为 LangChain 向量库打造管理工具集
python·ai·langchain
是一个Bug8 分钟前
LangChain 入门完全指南:核心概念、学习路线与实战 Demo
学习·langchain
牧子川21 分钟前
018-tool-decorator-basics
langchain·tools
-停泊1 小时前
Skill和Prompt有何不同
prompt·agent·skill
Nayxxu1 小时前
ChatGPT API 中转站技术选型与接入实测:从词元无忧 API(token5u API)开始更省事
人工智能·chatgpt
武子康1 小时前
调查研究-148 Deepseek-V4-Flash 生成式AI十大高频业务场景落地指南
大数据·人工智能·深度学习·ai·chatgpt·deepseek
tang&1 小时前
【LangGraph】LangGraph 协调者-工作者模式完全解析:从零构建一个智能报告生成系统
langchain
渣渣苏1 小时前
LangChain 的 Deep Agents:生产级智能体引擎的架构
架构·langchain·deep agents·harness
贺国亚1 小时前
01-Prompt工程-Few-Shot-CoT与Tool-Use
prompt
z小猫不吃鱼2 小时前
12 Prompt Engineering 入门:提示词为什么会影响模型行为?
人工智能·gpt·自然语言处理·prompt