gptApiTemplatemain.tsx13 matches
1import { blob } from "https://esm.town/v/std/blob";
2import { extractHttpEndpoint } from "https://esm.town/v/xkonti/extractHttpEndpoint?v=2";
3import { GptApi } from "https://esm.town/v/xkonti/gptApiFramework?v=67";
4import { z } from "npm:zod";
56// Configure API
78const api = new GptApi({
9url: extractHttpEndpoint(import.meta.url).toLowerCase(),
10title: "API Name",
11description: "The API for submitting fun Video Game Ideas",
12version: "1.0.0",
13policyGetter: async () => {
27}).describe("Description of the output");
2829api.jsonToJson({
30verb: "post",
31path: "/example",
34requestSchema: InputSchema,
35responseSchema: OutputSchema,
36}, async (ctx, input, apiKey) => {
37// Implementation of the /example endpoint
38return {
41});
4243// Serve the API
44export default api.serve();
4546// Privacy policy template in Markdown
47const privacyPolicy = `# <apiName> Privacy Policy
48Last Updated: <lastUpdated>
4950## 1. Introduction
51Welcome to <apiName>. This privacy policy outlines our practices regarding the collection, use, and sharing of information through <apiName>.
5253## 2. Data Collection and Use
54<apiName> allows users to store, retrieve, list, and delete data. The data stored can be of any type as inputted by the user. We do not restrict or control the content of the data stored. The API operates as a public database, where data can be accessed by any user. We do not tie or track data per user.
5556## 3. Data Security
57<apiName> is protected by an API key. Users should be aware that any data they input can be accessed, modified, or deleted by other users with access to the API key. Users are advised not to store sensitive, personal, or confidential information. We assume no responsibility for the security of the data stored. The API code is run and data is stored by val.town, a third-party service provider.
5859## 4. Changes to This Policy
extractHttpEndpointREADME.md1 match
45```typescript
6const apiUrl = extractHttpEndpoint(import.meta.url);
7```
gptApiFrameworkmain.tsx43 matches
5556/**
57* The API info object that is used to describe the API to the GPT.
58*/
59export interface ApiInfo {
60/**
61* The URL of the API. This should match the URL of your Val.
62*/
63url: string;
6465/**
66* The name of the API. It gives the GPT an idea about the purpose of the API.
67*/
68title: string;
6970/**
71* A short description of the API. It gives the GPT an idea about the purpose of the API.
72*/
73description: string;
7475/**
76* The version of the API. Required by the OpenAPI spec.
77*/
78version: string;
93return zodToJsonSchema(schema, {
94name: "schema",
95target: "openApi3",
96}).definitions?.schema ?? null;
97}
125126/**
127* Describes the paths of an OpenAPI spec.
128*/
129type Paths = {
136137/**
138* Assembles the paths of an OpenAPI spec from endpoint definitions.
139* @param endpoints The endpoint definitions to use.
140* @returns The paths of the OpenAPI spec.
141*/
142function getPathsDesc(endpoints: EndpointDefinition[]): Paths {
178179/**
180* Generates an OpenAPI spec for the defined API.
181* @param url The URL of the API.
182* @param title The title of the API.
183* @param description The description of the API.
184* @param version The version of the API.
185* @param endpoints The endpoint definitions to use.
186* @returns The OpenAPI spec.
187*/
188function getOpenApiSpec(
189url: string,
190title: string,
194) {
195return {
196openapi: "3.1.0",
197info: {
198title,
210211/**
212* A class representing a GPT API. It provides methods for registering
213* endpoints and serving the API.
214*/
215export class GptApi {
216private app = new Hono();
217private info: ApiInfo;
218private endpoints: EndpointDefinition[] = [];
219220/**
221* Creates a new GptApi instance.
222* @param info Configuration for the API.
223*/
224constructor(info: ApiInfo) {
225this.info = info;
226this.app.get("/gpt/schema", (ctx) => {
227const spec = getOpenApiSpec(
228this.info.url,
229this.info.title,
250251this.app.get("/", (ctx) => {
252return ctx.text(`OpenAPI spec: ${this.info.url}/gpt/schema\nPrivacy policy: ${this.info.url}/privacypolicy\n`);
253});
254}
262jsonToNothing<TRequestSchema extends z.Schema>(
263endpointDef: InEndpointDefinition<TRequestSchema>,
264handler: (ctx: Context, reqBody: z.infer<TRequestSchema>, apiKey: string | null) => Promise<number>,
265) {
266const handlerWrapper = async (ctx: Context) => {
271// TODO: Handle invalid data format
272273const apiKey = this.extractApiKey(ctx);
274const statusCode = await handler(ctx, parsedRequestData, apiKey);
275return ctx.body(null, statusCode as StatusCode);
276};
294nothingToJson<TResponseSchema extends z.Schema>(
295endpointDef: OutEndpointDefinition<TResponseSchema>,
296handler: (ctx: Context, apiKey: string | null) => Promise<z.infer<TResponseSchema>>,
297) {
298const handlerWrapper = async (ctx: Context) => {
299const apiKey = this.extractApiKey(ctx);
300const response = await handler(ctx, apiKey);
301302// Validate response data
327ctx: Context,
328reqBody: z.infer<TRequestSchema>,
329apiKey: string | null,
330) => Promise<z.infer<TResponseSchema>>,
331) {
338// TODO: Handle invalid data format
339340const apiKey = this.extractApiKey(ctx);
341const response = await handler(ctx, parsedRequestData, apiKey);
342343// Validate response data
388389/**
390* Returns a function that can be used to serve the API.
391*
392* @example ValTown usage:
393* ```ts
394* export default gptApi.serve();
395* ```
396*
397* @example Deno usage:
398* ```
399* const { fetch } = gptApi.serve();
400* export default { fetch };
401* ```
406407/**
408* Extracts API key from Bearer Auth header.
409*/
410private extractApiKey(ctx: Context): string | null {
411const authHeader = ctx.req.header("Authorization");
412if (!authHeader || !authHeader.startsWith("Bearer ")) {
414}
415416const apiKey = authHeader.split(" ")[1];
417return apiKey;
418}
419}
maroonArmadilloREADME.md1 match
1# Hono
23Here's an example using the [Hono](https://hono.dev/) server library with the [Web API](https://docs.val.town/api/web). It works great!
45
10data.append("file", file);
1112const res = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", {
13method: "POST",
14headers: {
gptApiTemplateREADME.md1 match
4- The GPT using it: [Game Idea Exchange GPT](https://chatgpt.com/g/g-8fryVV9cU-game-idea-exchange)
56Migrated from folder: Tuts/XkontiTech/gptApiTemplate
2324capturePostHogEvent(
25Deno.env.get("phProjectAPIKey"),
26webhookPayload.sender.login,
27"GitHub Star",
easyAQI_cachedREADME.md1 match
3Get the Air Quality Index (AQI) for a location via open data sources.
45It's "easy" because it strings together multiple lower-level APIs to give you a simple interface for AQI.
671. Accepts a location in basically any string format (ie "downtown manhattan")
resumeRecsmain.tsx3 matches
3const tokenBucket = new TokenBucket(5, 1/12);
45export async function getRecommendations(jobDescription, resume, apiKey) {
67if (!tokenBucket.consume()) {
9}
10
11const endpoint = 'https://api.openai.com/v1/chat/completions';
12const model = 'gpt-4';
1330method: 'POST',
31headers: {
32'Authorization': `Bearer ${apiKey}`,
33'Content-Type': 'application/json'
34},
story_wordcountmain.tsx2 matches
949596// Main function to execute the scraping process
97async function main() {
98const baseUrl = "https://forums.spacebattles.com/search/69363141/?t=post&c[content]=thread&c[users]=3ndless&o=date";
104console.log("Valid Feeds:", validFeeds);
105} catch (error) {
106console.error("Error during the scraping process:", error);
107}
108}