0.1.1 • Published 1 year ago

cloudflare-basics-ai-plugin v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

cloudflare-basics-ai-plugin

Simple Cloudflare Worker utilities for building OpenAI's AI plugins.

Uses cloudflare-basics.

Usage

import { Router, json, withZod } from 'cloudflare-basics'
import { addOpenApiRoute, addAiPluginRoute } from 'cloudflare-basics-ai-plugin'
import { z } from 'zod'

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext
  ): Promise<Response> {
    const router = new Router<Env>()

    const requestSchema = z.object({
      markdown: z.string(),
    })

    const responseSchema = z.object({
      success: z.boolean(),
    })

    const route = withZod<Env, z.infer<typeof requestSchema>>(
      requestSchema,
      async (options) => {
        console.log('Creating note', options.data.markdown)

        return json({ success: true })
      }
    )

    router.post('/notes', route)

    // Adds GET /openapi.json
    addOpenApiRoute(router, {
      title: 'Reflect Notes',
      description:
        'A plugin that allows the user to save notes. For example, saving a summary of their ChatGPT conversation history.',
      version: '1.0.0',
      paths: [
        {
          path: '/notes',
          method: 'post',
          summary: 'Create a note',
          requestSchema,
          responseSchema,
        },
      ],
    })

    // Adds GET /.well-known/ai-plugin.json
    addAiPluginRoute(router, {
      humanName: 'Reflect Notes',
      modelName: 'reflect_notes',
      humanDescription:
        'A plugin that allows the user to save notes. For example, saving a summary of their ChatGPT conversation history.',
      modelDescription:
        'Reflect notes plugin for ChatGPT. This plugin allows the user to save notes. For example, saving a summary of their ChatGPT conversation history.',
      contactEmail: 'support@reflect.app',
      legalInfoUrl: 'https://reflect.app/terms',
      logoUrl: 'https://logo.clearbit.com/reflect.app',
    })

    return (
      router.handle(request, env, ctx) ??
      new Response('Not Found', { status: 404 })
    )
  },
}
0.1.1

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago