# 操作简单,只需俩步


步骤一

首先获取你的 APIkey 格式为 sk-***************** 开头

步骤二

更改你的接口地址

  • 原来 https://api.openai.com
  • 现在 https://api.openai-hub.com 只需要在后面加上-hub即可
  • 市面上99%的程序都可以更改接口地址。如果是自己开发的系统,需要在代码里面修改。

有几个注意的地方:

# 以下是GPT对话接口各语言示例代码,仅测试gpt-3.5-turbo模型,其余模型请更改model参数 模型名称


# CURL 示例代码

curl --request POST 
--url https://api.openai-hub.com/v1/chat/completions 
--header 'Authorization: Bearer 替换为你的APIkey' 
-H "Content-Type: application/json" 
--data '{
"max_tokens": 4000,
"model": "gpt-3.5-turbo",
"temperature": 0.8,
"top_p": 1,
"presence_penalty": 1,
"messages": [
        {
        "role": "system",
        "content": "This system content"
        },
        {
        "role": "user",
        "content": "pls,say test!"
        }
    ]
}'

# Python调用示例代码

import os
from openai import OpenAI

client = OpenAI(
    api_key="你的接口密钥",
    base_url = "https://api.openai-hub.com/v1"
)

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

# php示例代码

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.openai-hub.com/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer 替换为你的APIkey';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = array(
    'max_tokens' => 3000,
    'model' => 'gpt-3.5-turbo',
    'temperature' => 0.8,
    'top_p' => 1,
    'presence_penalty' => 1,
    'messages' => array(
        array(
            'role' => 'system',
            'content' => 'This system content'
        ),
        array(
            'role' => 'user',
            'content' => 'pls,say test!'
        )
    )
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result;

# 小程序示例代码

wx.request({         
            url:'https://api.openai-hub.com/v1/chat/completions',
            method: 'POST',
            header: {
                'Content-Type': 'application/json',
                'Accept':'application/json',
                // 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)', 
                'Authorization': 'Bearer {}'
            },
          
            data:JSON.stringify({
              "model": "gpt-3.5-turbo",
              "messages": [
                  {
                      "role": "system",
                      "content": "You are a helpful assistant."
                  },
                  {
                      "role": "user",
                      "content": "你是谁"
                  }
              ]
          }),
            success: (result) => {
              
            },
        })
    },