How to enable OpenAI custom GPT to access an API?

1.2k views Asked by At

I'm trying to build a custom GPT that can access an API via the "Actions" configuration.

For illustration, I built the toy API below and deployed to https://main-bvxea6i-74oriiawvvtoy.eu-5.platformsh.site/.

Then I copied the automatically generated OpenAPI spec, added the server section (result below) and set up a Custom GPT via https://chat.openai.com/.

My GPT correctly identifies the 3 methods available in its configuration. It also states that it has access to those methods in the chat windows. But it cannot access them and reports errors like "Error talking to main-bvxea6i-74oriiawvvtoy.eu-5.platformsh.site" or "It seems that there's an issue with retrieving the message from the API, as the request resulted in a "Not Found" error."

Any idea what is going wrong?

(BTW, I can make a Custom GPT that simply lists all posts of https://jsonplaceholder.typicode.com/. Can Custom GPTs not work with parameters properly?)

Code

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 spec

{
    "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"
            }
        }
    }
}
1

There are 1 answers

2
Diego On

Be sure that you have a TLS certificate.

As custom GPTS has been released recently, there may be some bugs. OpenAI will release new features and improvements related with the "Actions" feature in the next weeks. For instance, now you can debug your requests and see what is happening.

enter image description here