Skip to content

samueli/smart_prompt_api

Repository files navigation

Smart Prompt API

A powerful and efficient API service for managing and optimizing AI prompts, built with Cloudflare Workers.

English | 简体中文

Features

  • 🚀 High Performance: Powered by Cloudflare Workers for global edge deployment
  • 🔒 Secure Authentication: Bearer token-based authentication system
  • 📝 Comprehensive API: Full CRUD operations for prompt management
  • 🔍 Smart Optimization: AI-powered prompt optimization capabilities
  • 🌐 Global Access: Low-latency access from anywhere in the world

Tech Stack

  • Runtime: Cloudflare Workers
  • Framework: Hono.js
  • Language: TypeScript
  • Testing: Jest
  • Database: Cloudflare D1 (SQLite)
  • Development: Wrangler CLI

Prerequisites

  • Node.js (v18 or later)
  • npm or yarn
  • Wrangler CLI (for Cloudflare Workers development)
  • Cloudflare Account with Workers and D1 database access

Getting Started

  1. Clone the repository:
git clone <repository-url>
cd smart_prompt_api
  1. Install dependencies:
npm install
  1. Copy configuration files:
cp wrangler.example.toml wrangler.toml
  1. Update wrangler.toml with your Cloudflare account details and D1 database configuration.

  2. Initialize the database with schema:

wrangler d1 execute DB --local --file=./schema.sql
  1. Start development server:
npm run dev

Database Schema

The project uses Cloudflare D1 (SQLite) with the following schema:

CREATE TABLE prompts (
    id TEXT PRIMARY KEY,
    tags TEXT,
    creator TEXT NOT NULL,
    create_time TEXT NOT NULL,
    update_time TEXT NOT NULL,
    status INTEGER DEFAULT 1,
    is_public INTEGER DEFAULT 0,
    source_prompt TEXT NOT NULL,
    optimized_prompt TEXT,
    token TEXT
);

API Documentation

Detailed API documentation can be found in API Documentation. Key endpoints include:

Prompt Management

  • GET /api/prompts - List prompts with filtering and sorting
  • POST /api/prompts - Create or update a prompt
  • DELETE /api/prompts/:id - Delete a prompt
  • PATCH /api/prompts/:id/visibility - Update prompt visibility

Authentication

All API endpoints require Bearer token authentication:

Authorization: Bearer <your_token>

Development

Running Tests

npm test

Local Development

npm run dev

The development server will start at http://localhost:8787

Environment Variables

Configure the following in your wrangler.toml:

  • DB - D1 database binding
  • Other environment-specific variables

Deployment

  1. Ensure your Cloudflare account is configured:
wrangler login
  1. Deploy the application:
npm run deploy

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages