如何启用 OpenAI 自定义 GPT 访问 API?

How to enable OpenAI custom GPT to access an API?

提问人:myke 提问时间:11/14/2023 更新时间:11/21/2023 访问量:132

问:

我正在尝试构建一个可以通过“操作”配置访问 API 的自定义 GPT。

为了说明这一点,我在下面构建了玩具 API 并部署到 https://main-bvxea6i-74oriiawvvtoy.eu-5.platformsh.site/

然后,我复制了自动生成的 OpenAPI 规范,添加了服务器部分(下面的结果)并通过 https://chat.openai.com/ 设置了自定义 GPT。

我的 GPT 正确识别了其配置中可用的 3 种方法。它还声明它可以在聊天窗口中访问这些方法。但它无法访问它们并报告错误,例如“与 main-bvxea6i-74oriiawvvtoy.eu-5.platformsh.site 通信时出错”或“从 API 检索消息时似乎存在问题,因为请求导致”未找到“错误。

知道出了什么问题吗?

(顺便说一句,我可以制作一个自定义 GPT,只需列出 https://jsonplaceholder.typicode.com/ 的所有帖子。自定义 GPT 无法正确使用参数吗?

法典

import os
import uvicorn
from typing import Union
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def home():
    return "Home sweet home"


@app.get("/message")
def message():
    return {"msg": "The early bird catches the worm."}


@app.get("/calc/{x}")
def calc(x: int, y: Union[int, None] = None):
    y = y or 0
    return {"x": x, "y": y, "result": int(x) * int(y)}


if __name__ == "__main__":
    port = os.getenv("PORT") or 8080
    uvicorn.run(app, host="127.0.0.1", port=int(port))

OpenAPI 规范

{
    "openapi": "3.1.0",
    "info": {
        "title": "FastAPI",
        "version": "0.1.0"
    },
    "servers": [
        {
            "url": "https://main-bvxea6i-74oriiawvvtoy.eu-5.platformsh.site/"
        }
    ],
    "paths": {
        "/": {
            "get": {
                "summary": "Home",
                "operationId": "home__get",
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        }
                    }
                }
            }
        },
        "/message": {
            "get": {
                "summary": "Message",
                "operationId": "message_message_get",
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        }
                    }
                }
            }
        },
        "/calc/{x}": {
            "get": {
                "summary": "Calc",
                "operationId": "calc_calc__x__get",
                "parameters": [
                    {
                        "name": "x",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer",
                            "title": "X"
                        }
                    },
                    {
                        "name": "y",
                        "in": "query",
                        "required": false,
                        "schema": {
                            "anyOf": [
                                {
                                    "type": "integer"
                                },
                                {
                                    "type": "null"
                                }
                            ],
                            "title": "Y"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/HTTPValidationError"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "HTTPValidationError": {
                "properties": {
                    "detail": {
                        "items": {
                            "$ref": "#/components/schemas/ValidationError"
                        },
                        "type": "array",
                        "title": "Detail"
                    }
                },
                "type": "object",
                "title": "HTTPValidationError"
            },
            "ValidationError": {
                "properties": {
                    "loc": {
                        "items": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "integer"
                                }
                            ]
                        },
                        "type": "array",
                        "title": "Location"
                    },
                    "msg": {
                        "type": "string",
                        "title": "Message"
                    },
                    "type": {
                        "type": "string",
                        "title": "Error Type"
                    }
                },
                "type": "object",
                "required": [
                    "loc",
                    "msg",
                    "type"
                ],
                "title": "ValidationError"
            }
        }
    }
}
开放API GPT-4

评论


答:

0赞 Diego 11/21/2023 #1

确保您拥有 TLS 证书。

由于自定义 GPTS 最近发布,因此可能存在一些错误。OpenAI 将在未来几周内发布与“操作”功能相关的新功能和改进。例如,现在您可以调试您的请求并查看发生了什么。

enter image description here

评论

0赞 myke 11/22/2023
谢谢!存在有效的 TLS 证书。― 我没有看到调试输出。您是否必须激活某些设置才能获得此设置?
0赞 Diego 11/29/2023
当您构建/编辑自定义 GPT 时,您必须转到 Action 配置并测试端点。单击“测试”后,您可以看到调试输出。