Skip to content

Streamlined API for simplified OpenAI requests, enabling efficient AI integration... Created at https://coslynx.com

Notifications You must be signed in to change notification settings

coslynx/OpenAI-Python-Wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

OpenAI Python Wrapper

A Python backend service for seamless OpenAI API integration.

Developed with the software and tools below.

Framework used Programming Language Database used Large Language Models
git-last-commit GitHub commit activity GitHub top language

πŸ“‘ Table of Contents

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

πŸ“ Overview

This repository contains the backend code for the OpenAI Python Wrapper, a Python service designed to simplify the use of OpenAI's API for developers. This service offers a user-friendly interface for sending requests to OpenAI's API and receiving structured responses, making it easier for developers to integrate AI capabilities into their Python applications.

πŸ“¦ Features

Feature Description
βš™οΈ Architecture The service follows a modular architectural pattern with separate directories for different functionalities, ensuring easier maintenance and scalability.
πŸ“„ Documentation This repository includes a README file that provides a detailed overview of the project, its dependencies, and usage instructions.
πŸ”— Dependencies The codebase relies on various external libraries and packages such as fastapi, uvicorn, openai, pydantic, and sqlalchemy, which are essential for building and managing the API, interacting with OpenAI, and managing data.
🧩 Modularity The modular structure allows for easier maintenance and reusability of the code, with separate directories and files for different functionalities such as services, routes, models, and utilities.
πŸ§ͺ Testing Unit tests using pytest are implemented to ensure the reliability and robustness of the codebase.
⚑️ Performance The service is optimized for efficiency, leveraging asynchronous operations with FastAPI.
πŸ” Security Security is enhanced by implementing measures such as API key handling through environment variables and input validation using Pydantic.
πŸ”€ Version Control Utilizes Git for version control.
πŸ”Œ Integrations The service seamlessly integrates with the OpenAI API and leverages the openai library for efficient interaction.
πŸ“Ά Scalability Designed for scalability, using a framework like FastAPI which supports asynchronous operations and can easily handle increased user load and data volume.

πŸ“‚ Structure

openai-python-wrapper/
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .env
β”œβ”€β”€ main.py
β”œβ”€β”€ models/
β”‚   └── base.py
β”œβ”€β”€ services/
β”‚   └── openai_service.py
β”œβ”€β”€ utils/
β”‚   └── openai_utils.py
β”œβ”€β”€ routes/
β”‚   └── api_routes.py
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_routes.py
β”‚   β”œβ”€β”€ test_models.py
β”‚   β”œβ”€β”€ test_utils.py
β”‚   └── test_services.py
β”œβ”€β”€ commands.json
β”œβ”€β”€ startup.sh
β”œβ”€β”€ logging.conf
└── .gitignore

πŸ’» Installation

πŸ”§ Prerequisites

  • Python 3.9+
  • pip package manager
  • PostgreSQL (optional)

πŸš€ Setup Instructions

  1. Clone the repository:

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

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

    • Create a .env file in the project root and fill in the required values:
      OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE
      DATABASE_URL=postgresql://user:password@host:port/database
  4. (Optional) Set up the PostgreSQL database:

    • Follow the instructions for setting up PostgreSQL on your system.
    • Update the DATABASE_URL in the .env file with your PostgreSQL connection details.

πŸ—οΈ Usage

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

  1. Start the development server:
    uvicorn app:app --host 0.0.0.0 --port 8000 --reload

🌐 Hosting

πŸš€ Deployment Instructions

Deploying to Heroku

  1. Install the Heroku CLI:

    npm install -g heroku
  2. Login to Heroku:

    heroku login
  3. Create a new Heroku app:

    heroku create OpenAI-Python-Wrapper-production
  4. Set up environment variables:

    heroku config:set OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE
    heroku config:set DATABASE_URL=your_database_url_here
  5. Deploy the code:

    git push heroku main
  6. Run database migrations (if applicable):

    heroku run python manage.py migrate

πŸ”‘ Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key.
  • DATABASE_URL: Connection string for your PostgreSQL database (if applicable).

πŸ“œ API Documentation

πŸ” Endpoints

  • POST /api/generate_text

    • Description: Generates text using OpenAI's API.
    • Body:
      {
        "prompt": "Write a short story about a cat.",
        "model": "text-davinci-003",
        "max_tokens": 100
      }
    • Response:
      {
        "text": "Once upon a time, there was a fluffy cat named Mittens..."
      }
  • POST /api/translate_text

    • Description: Translates text between languages using OpenAI's API.
    • Body:
      {
        "text": "Hello, world!",
        "target_language": "fr"
      }
    • Response:
      {
        "translation": "Bonjour le monde !"
      }
  • POST /api/complete_code

    • Description: Completes code snippets using OpenAI's API.
    • Body:
      {
        "prompt": "def greet(name):\n  print("
      }
    • Response:
      {
        "code": "def greet(name):\n  print(f\"Hello, {name}!\")"
      }

πŸ“œ 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-Python-Wrapper

πŸ“ž 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!