gptApiFramework
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Allows for automatic generation of Hono API compatible with GPTs. Endpoints' inputs and outputs need to be specified via types from which the Open API spec is generated automatically and available via /gpt/schema
endpoint.
⚠️ Breaking changes introduced in v23 & 24:
nothingToJson
doesn't take the genericTResponse
anymore. The type is inferred from the endpoint definition. The endpoint definition doesn't need therequestSchema
,requestDesc
andresponseDesc
defined anymore. The descriptions are inferred from the schema description.jsonToJson
doesn't take the genericTRequest
andTResponse
anymore. Types are inferred from the endpoint definition. The endpoint definition doesn't need therequestDesc
andresponseDesc
defined anymore. The descriptions are inferred from the schema description.
Usage example:
import { GptApi } from "https://esm.town/v/xkonti/gptApiFramework";
import { z } from "npm:zod";
/**
* COMMON TYPES
*/
const ResponseCommandSchema = z.object({
feedback: z.string().describe("Feedback regarding submitted action"),
command: z.string().describe("The command for the Mediator AI to follow strictly"),
data: z.string().optional().describe("Additional data related to the given command"),
}).describe("Contains feedback and further instructions to follow");
/**
* INITIALIZE API
*/
const api = new GptApi({
url: "https://xkonti-planoverseerai.web.val.run",
title: "Overseer AI API",
description: "The API for interacting with the Overseer AI",
version: "1.0.0",
policyGetter: async () => {
const { markdownToPrettyPage } = await import("https://esm.town/v/xkonti/markdownToHtmlPage?v=5");
return await markdownToPrettyPage("# Privacy Policy\n\n## Section 1...");
},
});
/**
* REQUIREMENTS GATHERING ENDPOINTS
*/
api.nothingToJson({
verb: "POST",
path: "/newproblem",
operationId: "new-problem",
desc: "Endpoint for informing Overseer AI about a new problem presented by the User",
responseSchema: ResponseCommandSchema,
responseDesc: "Instruction on how to proceed with the new problem",
}, async (ctx) => {
return {
feedback: "User input downloaded. Problem analysis is required.",
command: await getPrompt("analyze-problem"),
data: "",
};
});
export default api.serve();
Migrated from folder: GPTs/ApiFramework/gptApiFramework