背景介绍

在这里插入图片描述
在这里插入图片描述
OpenAi-HK官网
总之就是,国内使用直接调openAI官方的API接口各种限制,包括需要科学上网,购买虚拟信用卡进行充值,而且付费高。所以这里采用openAi-HK的中转方式,先访问openAi-HK,然后由openAi-HK再请求openAi接口。可以把openAi-HK理解为一个代理中间商。
openAi-HK登录简便,只需要微信扫码关注,即可登录。登陆入口

注册登陆及操作的介绍

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

以快速接入中提供的Python版脚本为例演示

import requests
import json

url = "https://api.openai-hk.com/v1/chat/completions"

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer 替换为你的API Key"
}

data = {
    "max_tokens": 1200,
    "model": "gpt-3.5-turbo",
    "temperature": 0.8,
    "top_p": 1,
    "presence_penalty": 1,
    "messages": [
        {
            "role": "system",
            "content": "You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible."
        },
        {
            "role": "user",
            "content": "你是chatGPT多少?"
        }
    ]
}

执行完的响应回复:

 {
   "id": "chatcmpl-BTVpO13P2rHLdhf5eg1MPSllxj8V",
   "object": "chat.completion",
   "created": 1752569925,
   "model": "gpt-3.5-turbo-0125",
   "choices": [
     {
       "index": 0,
       "message": {
         "role": "assistant",
         "content": "我是基于GPT-3.5架构的ChatGPT。",
         "refusal": null,
         "annotations": []
       },
       "logprobs": null,
       "finish_reason": "stop"
     }
   ],
   "usage": {
     "prompt_tokens": 39,
     "completion_tokens": 14,
     "total_tokens": 53,
     "prompt_tokens_details": {
       "cached_tokens": 0,
       "audio_tokens": 0
     },
     "completion_tokens_details": {
       "reasoning_tokens": 0,
       "audio_tokens": 0,
       "accepted_prediction_tokens": 0,
       "rejected_prediction_tokens": 0
     }
   },
   "service_tier": "default",
   "system_fingerprint": null
 }

从响应的结果也可以得知:本次提问+回答共消耗的tokens数为:53个。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐