便携AI网
AI的百科全书

便携AI聚合API gpt-4-gizmo-*(官方GPTs)模型接入教程

GPTs是ChatGPT的插件功能,其实就是在某方面强化后的ChatGPT,可以让ChatGPT在特定一领域更专业些(例如学术、写稿等)。便携AI聚合API支持通过gpt-4-gizmo-*模型调用官方GPTs,自动识别链接,下面分享下接入教程。

一、前言

本文参考OpenAI官方API文档:

文中使用的API Key均为便携AI聚合API后台生成的令牌,以sk-开头的一串随机字符,获取方法:《便携AI聚合API新建令牌(API key)教程》。

便携AI聚合API有三个接入地址(即URL),一般推荐选择第一个或者第二个:

  • 中转API调用地址①(中国香港服务器,直连线路,带宽大):https://api.bianxie.ai
  • 中转API调用地址②(国内上海服务器,带宽稍小):https://api.bianxieai.com
  • 中转API调用地址③(国外服务器,也可以直连,备用):https://api.a8.hk(三个网站都可以登录账号,数据同步)

模型支持各种语言接入,包括python、PHP、C#、C、Ruby、Java、Go、JavaScript等,本文主要分享官方的CURL调用方法,以及基于python的调用方法,如果你是用其他语言调用API的,则直接问ChatGPT或者其他语言模型怎么改写就行了,如下图:

不同语言调用便携AI聚合API

二、gpt-4-gizmo-*模型接入教程

gpt-4-gizmo-*模型是用来调用GPTs的,调用前需要找到这个GPTs的特定编号,有两个方法可以找到。

1、ChatGPT官网查询

登录ChatGPT,点击左侧的【Explore GPTs】,搜索需要使用的GPTs:

gpt-4-gizmo-*模型接入教程

找到后点击【Start Chat】:

gpt-4-gizmo-*模型接入教程

这里的“g-B3hgivKK9”就是这个GPTs的编号:

gpt-4-gizmo-*模型接入教程

2、gptshunter查询

地址:https://www.gptshunter.com

找到需要的GPTs,点击【Use *** on ChatGPT】,链接里同样会包含这个GPTs的ID:

gpt-4-gizmo-*模型接入教程

找到GPTs的ID后,修改模型名称,例如这里就是gpt-4-gizmo-g-B3hgivKK9,之后的调用方法跟gpt模型的调用方法一样,支持多种参数,必须的就是modelmessages,其他参数如temperaturemax_tokens可以让你自定义这次请求的设置,具体每个参数的意思大家可以参考官网

python调用示例:

import requests
api_key = 'sk-Xy3WuCpTTvY19g'
url = 'https://api.bianxie.ai/v1/chat/completions'

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {api_key}'
}

data = {
    'model': 'gpt-4-gizmo-g-B3hgivKK9',
    'messages': [{'role': 'user', 'content': 'Write me a 200 word product description for a red screwdriver. '}],
}

response = requests.post(url, headers=headers, json=data)

print(response.json())

返回示例:

{
    'id': 'chatcmpl-89Dc6IVZ14IQC4rp6gdG8D2nVV3JK',
    'object': 'chat.completion',
    'created': 1717555182,
    'model': 'gpt-4-gizmo-g-B3hgivKK9',
    'choices': [{
        'index': 0,
        'message': {
            'role': 'assistant',
            'content': "**Product Description: Red Screwdriver**\n\nIntroducing our sleek and efficient Red Screwdriver, the perfect tool for your everyday fixing needs. Crafted with precision engineering and durability in mind, this screwdriver ensures reliable performance for any project. Its vibrant red color adds a touch of style to your toolkit while providing ease of identification amidst clutter.\n\nDesigned for versatility, the Red Screwdriver features a comfortable grip handle that fits securely in your hand, reducing fatigue during prolonged use. Whether you're assembling furniture, repairing electronics, or tackling household tasks, this screwdriver delivers exceptional torque and control, making it a must-have for DIY enthusiasts and professionals alike.\n\nConstructed from high-quality materials, this screwdriver is built to withstand the rigors of frequent use, ensuring longevity and reliability. The corrosion-resistant coating protects against rust and wear, extending the lifespan of the tool. With its magnetic tip, the Red Screwdriver securely holds screws in place, preventing frustrating drops and enhancing efficiency.\n\nUpgrade your toolkit with the Red Screwdriver and experience the perfect combination of performance, durability, and style. Whether you're a seasoned craftsman or a weekend warrior, this screwdriver is the ultimate companion for all your projects."
        },
        'finish_reason': 'stop'
    }],
    'usage': {
        'prompt_tokens': 22,
        'completion_tokens': 237,
        'total_tokens': 259
    }
}
赞(0)
未经允许不得转载:便携AI » 便携AI聚合API gpt-4-gizmo-*(官方GPTs)模型接入教程