Skip to content

Streamline OpenAI requests with an intuitive API wrapper... Created at https://coslynx.com

Notifications You must be signed in to change notification settings

coslynx/OpenAI-API-Wrapper-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OpenAI-API-Wrapper-Python

A Python backend service that simplifies interaction with OpenAI's API

Developed with the software and tools below.

Framework: FastAPI Backend: Python Database: PostgreSQL LLMs: OpenAI
git-last-commit GitHub commit activity GitHub top language

πŸ“‘ Table of Contents

  • πŸ“ Overview
  • πŸ“¦ Features
  • πŸ“‚ Structure
  • πŸ’» Installation
  • πŸ—οΈ Usage
  • 🌐 Hosting
  • πŸ“„ License
  • πŸ‘ Authors

πŸ“ Overview

This repository contains a Minimum Viable Product (MVP) for a Python backend service called "AI Wrapper for OpenAI Requests". This service simplifies interacting with OpenAI's API by providing a user-friendly wrapper that handles request formatting, authentication, and response parsing.

πŸ“¦ Features

Feature Description
βš™οΈ Architecture A robust and efficient architecture built using FastAPI, PostgreSQL, and the OpenAI Python library.
πŸ“„ Documentation Clear and detailed documentation explaining the MVP's functionalities, setup, and usage.
πŸ”— Dependencies Leverages carefully selected Python libraries for efficient development and robust functionality.
🧩 Modularity Well-structured codebase with separate modules for different functionalities, promoting code reusability and maintainability.
πŸ§ͺ Testing Includes unit tests to ensure the correctness and reliability of the core components.
⚑️ Performance Optimized for efficient request handling and response processing, ensuring fast and responsive results.
πŸ” Security Implements secure API key management and access control using JWT authentication.
πŸ”€ Version Control Utilizes Git for version control, ensuring collaboration and trackability of changes.
πŸ”Œ Integrations Seamless integration with OpenAI's API using the official Python library.
πŸ“Ά Scalability Designed with scalability in mind to handle growing request volumes.

πŸ“‚ Structure

β”œβ”€β”€ core
β”‚   β”œβ”€β”€ services
β”‚   β”‚   └── openai_service.py
β”‚   └── models
β”‚       └── models.py
β”œβ”€β”€ utils
β”‚   └── logger.py
β”œβ”€β”€ tests
β”‚   └── test_services.py
β”œβ”€β”€ db
β”‚   β”œβ”€β”€ models
β”‚   β”‚   └── __init__.py
β”‚   └── schemas
β”‚       └── __init__.py
β”œβ”€β”€ config
β”‚   └── settings.py
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .env
β”œβ”€β”€ startup.sh
β”œβ”€β”€ commands.json
β”œβ”€β”€ requirements.txt
└── main.py

πŸ’» Installation

πŸ”§ Prerequisites

  • Python 3.9+
  • PostgreSQL 14+
  • pip (Python package manager)
  • Docker (Optional for local development)

πŸš€ Setup Instructions

  1. Clone the repository:

    git clone https://github.com/coslynx/OpenAI-API-Wrapper-Python.git
    cd OpenAI-API-Wrapper-Python
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables:

    • Create a .env file in the root directory of the project.
    • Add the following environment variables, replacing the placeholders with your actual values:
      OPENAI_API_KEY=YOUR_OPENAI_API_KEY
      DATABASE_URL=postgres://user:password@host:port/database
      JWT_SECRET_KEY=YOUR_JWT_SECRET_KEY
      
  4. Start the database (optional):

    • If you're using Docker for local development, start the PostgreSQL database container:
      docker-compose up -d db
  5. Run the application:

    uvicorn main:app --reload

πŸ—οΈ Usage

πŸƒβ€β™‚οΈ Running the MVP

  1. Start the development server:
    uvicorn main:app --reload
  2. Access the API:
    • The API is now running at http://localhost:8000/.
    • You can send requests using tools like curl or Postman.

βš™οΈ Configuration

  • Environment Variables: The application reads settings from the .env file, so you can customize it to suit your environment.

🌐 Hosting

πŸš€ Deployment Instructions

  1. Create a virtual environment:
    python3 -m venv .venv
  2. Activate the virtual environment:
    source .venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Set up your database:
    • Ensure you have a PostgreSQL database set up and configured.
    • Update the DATABASE_URL environment variable in your .env file with the correct connection string.
  5. Create a deployment script:
    • You can use a script like startup.sh to automate the deployment process.
  6. Deploy the code:
    • Choose a deployment platform (e.g., Heroku, AWS Lambda, Google Cloud Functions) and follow their specific deployment instructions.

πŸ”‘ Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key.
  • DATABASE_URL: The connection string for your PostgreSQL database.
  • JWT_SECRET_KEY: A secret key for signing JWT tokens (used for authentication).

πŸ“œ API Documentation

πŸ” Endpoints

  • POST /generate:
    • Description: Generate text using an OpenAI model.
    • Body: { "text": "Your input text", "model": "The OpenAI model name (e.g., gpt-3.5-turbo)" }
    • Response: { "text": "Generated text" }
  • POST /translate:
    • Description: Translate text between languages using an OpenAI model.
    • Body: { "text": "Your input text", "model": "The OpenAI translation model (e.g., gpt-3.5-turbo)", "target_language": "The target language code (e.g., 'fr', 'es', 'de')" }
    • Response: { "text": "Translated text" }
  • POST /register:
    • Description: Register a new user.
    • Body: { "username": "Your username", "password": "Your password" }
    • Response: { "message": "Registration successful!" }
  • POST /login:
    • Description: Log in an existing user.
    • Body: { "username": "Your username", "password": "Your password" }
    • Response: { "token": "JWT access token" }

πŸ”’ Authentication

  1. Register or Log In: New users can register using the /register endpoint. Existing users can log in using the /login endpoint.
  2. Obtain JWT Token: Upon successful registration or login, the server returns a JWT access token.
  3. Authorization: Include the JWT access token in the Authorization header of all subsequent requests to the API.

πŸ“œ License & Attribution

πŸ“„ License

This Minimum Viable Product (MVP) is licensed under the GNU AGPLv3 license.

πŸ€– AI-Generated MVP

This MVP was entirely generated using artificial intelligence through CosLynx.com.

No human was directly involved in the coding process of the repository: OpenAI-API-Wrapper-Python

πŸ“ž Contact

For any questions or concerns regarding this AI-generated MVP, please contact CosLynx at:

🌐 CosLynx.com

Create Your Custom MVP in Minutes With CosLynxAI!