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.
Viewing readonly version of main branch: v6View latest version
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:
nothingToJsondoesn't take the genericTResponseanymore. The type is inferred from the endpoint definition. The endpoint definition doesn't need therequestSchema,requestDescandresponseDescdefined anymore. The descriptions are inferred from the schema description.jsonToJsondoesn't take the genericTRequestandTResponseanymore. Types are inferred from the endpoint definition. The endpoint definition doesn't need therequestDescandresponseDescdefined 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