Skip to content

Angel-del-dev/Async-AI-Prompt-Queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI prompt processing queue API

A simple queue API to securely store AI prompts for async processing.

This is a multirepo project, Whilst this API should be deployed on a VPS or hosting, it requires an active Local worker deployed on a device with a graphics card and plenty RAM to function correctly.

Features

  • Security: JWT Auth.
  • Scalability: Rate Limiting.
  • Async: Add jobs to a queue to later fetch the result.
  • Modularity: Clear responsability separation between domains (Auth, Jobs).

Instalation and configuration

git clone https://github.com/Angel-del-dev/Async-AI-Prompt-Queue.git async-au-prompt-queue
cd async-au-prompt-queue
go mod download
cp .env-example .env
# Database schema can be found in the following file
/schema/db.sql
--psql
-- Create a user to test the api
|> insert into users(name, password) values ('...', '...');

Structure and execution

Dependencies

  • github.com/gofiber/fiber/v3: Go Web framework.
  • github.com/jackc/pgx/v5: PostgreSQL driver.
  • golang.org/x/crypto/bcrypt: Secure hash creation/validation.

Server startup

cd scripts
./runbuild.sh

Prerequisites

  • Go (Versión 1.20+, preferably 1.25)
  • PostgreSQL engine.

Environment variables (.env)

Project startup depends on .env variables.

Var Description Type Required Domain
DB_HOST Database host. string true DB
DB_NAME Database name. string true DB
DB_USER Database username. string true DB
DB_PASSWORD Database password. string true DB
DB_PORT Database port. int true DB
DB_SSLMODE Database sslmode. string true DB
MAX_REQUESTSPERMINUTE Rate limiting. int true RATE_LIMIT
APP_PORT Fiber server port. int true FIBER
JWT_SECRET JWT Hash key. string true JWT

API Endpoints

1. Authentication (/auth)

Endpoint:

Obtains a JWT token

  • Method: POST
  • Endpoint: /auth
  • Middleware: ContentTypeAllowed("application/json")
  • Request body:
    {
        "user": "<string>", 
        "password": "<string>"
    }
  • Response (200 OK): Returns auth token and expiration date
    {
        "access_token": "<string>", 
        "expires_at": "<string>", 
        "expires_in": "<integer>" 
    }

2. Jobs (/jobs)

Endpoint: Create request job

Adds a prompt to the queue

  • Method: POST
  • Route: /jobs
  • Middleware: JWT Middleware, Content Type JSON.
  • Request body:
    {
        "system": "<string>", 
        "prompt": "<string>"
    }
    // 'system' or 'prompt' may be empty but at least one of them must be a valid prompt
  • Response (201 Created): { "job_id": "<integer>" }
  • Errors:
    • 400 Bad Request: Invalid or insufficient parameters.
    • 403 Forbidden: Invalid JWT Token.
    • 500 Internal Server Error: Serverside error.

Endpoint: Get Job result

Checks the status and result of the provided job

  • Method: GET
  • Route: /jobs/{job_id:"<integer>""}
  • Middleware: JWT Middleware.
  • Response: Still being processed(202 Accepted):
{
    "status":   "In progress",
    "response": null,
}
  • Response: Processed(200 OK):
{
    "status":   "Completed",
    "response": "<string>",
}
  • Errors:
    • 403 Forbidden: Invalid JWT Token.
    • 500 Internal Server Error: Serverside error.

About

Async AI prompt processing API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors