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

相关推荐
智泊AI6 小时前
RAG是什么?一文讲清:RAG检索增强生成!
llm
吴佳浩6 小时前
为什么"骂"大模型,它反而更聪明了?
人工智能·llm
Font Tian6 小时前
GPT-oss + vLLM + LobalChat
人工智能·gpt·llm
小新学习屋7 小时前
大模型-智能体-【篇四: Agent GPT 、AgentTuning、LangChain-Agent】
gpt·langchain·大模型·智能体
大模型教程9 小时前
GraphRAG绝对是以后RAG的潮流,不服来辩
程序员·llm·agent
AI大模型9 小时前
Spring AI 番外篇03:本地RAG使用百炼知识库
程序员·llm·agent
AI大模型9 小时前
Spring AI 番外篇02:还在为 AI Agent 调试头秃?Spring AI Alibaba Admin 来救场了!
程序员·llm·agent
AI大模型9 小时前
Spring AI 番外篇01:MCP Streamable HTTP 模式
程序员·llm·mcp
马尚道10 小时前
helloworld入门【从0到1,LangChain+RAG全链路实战AI知识库】
langchain
蛋先生DX10 小时前
RAG 切片利器 LumberChunker 是如何智能地把文档切割成 LLM 爱吃的块
llm·aigc·ai编程