Skip to content

Latest commit

 

History

History
165 lines (115 loc) · 3.2 KB

File metadata and controls

165 lines (115 loc) · 3.2 KB

OpenAPI Spec Generator

This FastAPI application generates OpenAPI v3 specifications based on user prompts using an AI model. It also logs all requests and responses.

Table of Contents

Features

  • Generate OpenAPI v3 specifications from user prompts
  • Log all requests and responses
  • Retrieve logs of past interactions
  • Dockerized application for easy deployment

Requirements

  • Python 3.12+
  • FastAPI
  • Pydantic
  • OpenAI Python Client
  • Peewee ORM
  • Uvicorn ASGI server

Installation

  1. Clone the repository:

    git clone https://github.com/0xstackforge/openapi-spec-generator.git
    cd openapi-spec-generator
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    
  3. Install the required packages:

    pip install -r requirements.txt
    

Usage

  1. Start the FastAPI server:

    uvicorn main:app --reload
    
  2. The API will be available at http://localhost:8000

  3. Use the /openapi-spec-generator endpoint to generate OpenAPI specifications

  4. View logs using the /logs endpoint

API Endpoints

POST /openapi-spec-generator

Generate an OpenAPI v3 specification based on a user prompt.

Request Body:

{
  "prompt": "Create an API for a todo list application"
}

Response:

A JSON object containing the generated OpenAPI v3 specification.

GET /logs

Retrieve the logs of past interactions.

Query Parameters:

  • limit (optional): Number of log entries to return (default: 1000)

Response:

An array of log entries, each containing:

  • timestamp: The time of the request
  • request: The original request
  • response: The generated response

Database

The application uses SQLite to store logs. The database file ai_service.db will be created in the project root directory.

Docker Deployment

Local Development with Docker Compose

Prerequisites

  • Docker
  • Docker Compose

Steps

  1. Build and start the services:
docker-compose up --build
  1. Access the application:
  1. Stop the services:
docker-compose down

Running with Docker

To run the application using Docker directly:

  1. Build the Docker image:

    docker build -t openapi-spec-generator .
    
  2. Run the container:

    docker run -p 8000:8000 openapi-spec-generator
    

The API will be available at http://localhost:8000

Entity Relationship Diagram

erDiagram
    LogEntry {
        int id PK
        datetime timestamp
        text request
        text response
    }
Loading

Contributing

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

License