Skip to content

Simplified API for seamless OpenAI requests, streamlining access to AI capabilities... Created at https://coslynx.com

Notifications You must be signed in to change notification settings

coslynx/OpenAI-API-Wrapper-Python-MVP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OpenAI-API-Wrapper-Python-MVP

Streamlined Python Backend for Effortless OpenAI API Interactions

Developed with the software and tools below.

FastAPI Framework Python Language OpenAI API 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 a Minimum Viable Product (MVP) called "OpenAI-API-Wrapper-Python-MVP" that simplifies interacting with OpenAI's powerful language models through a Python backend service. This MVP empowers developers to leverage AI capabilities without the complexity of directly working with the OpenAI API.

πŸ“¦ Features

Feature Description
βš™οΈ Architecture The codebase follows a modular structure, separating functionalities into distinct modules for easier maintenance and scalability.
πŸ“„ Documentation This README.md file provides a detailed overview of the MVP, its dependencies, and usage instructions.
πŸ”— Dependencies The codebase relies on several external libraries and packages, including fastapi, uvicorn, pydantic, openai, and requests.
🧩 Modularity The modular structure allows for easier maintenance and reusability of the code, with separate directories and files for different functionalities.
πŸ§ͺ Testing Includes unit tests to ensure the codebase is reliable and robust.
⚑️ Performance The MVP is optimized for performance and efficiency, using asynchronous processing and other techniques.
πŸ” Security The code implements basic security measures such as API key management and input validation.
πŸ”€ Version Control Uses Git for version control and GitHub Actions for automated builds and releases.
πŸ”Œ Integrations Integrates seamlessly with the OpenAI API, enabling various AI tasks like text generation, translation, question answering, and code completion.

πŸ“‚ Structure

β”œβ”€β”€ main.py
β”œβ”€β”€ routers
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ generate.py
β”‚   β”œβ”€β”€ translate.py
β”‚   β”œβ”€β”€ question.py
β”‚   └── code.py
β”œβ”€β”€ services
β”‚   β”œβ”€β”€ openai_service.py
β”‚   └── auth_service.py
β”œβ”€β”€ models
β”‚   β”œβ”€β”€ request.py
β”‚   └── response.py
β”œβ”€β”€ utils
β”‚   β”œβ”€β”€ logger.py
β”‚   β”œβ”€β”€ exceptions.py
β”‚   β”œβ”€β”€ config.py
β”‚   └── auth.py
└── tests
    └── test_main.py

πŸ’» Installation

πŸ”§ Prerequisites

πŸš€ Setup Instructions

  1. Clone the repository:

    git clone https://github.com/coslynx/OpenAI-API-Wrapper-Python-MVP.git
    cd OpenAI-API-Wrapper-Python-MVP
  2. Create a virtual environment (optional):

    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Configure environment variables:

    cp .env.example .env
    # Fill in your OpenAI API key:
    OPENAI_API_KEY=<your_openai_api_key>

πŸ—οΈ Usage

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

  1. Start the FastAPI server:
    uvicorn main:app --host 0.0.0.0 --port 8000

🌐 Hosting

πŸš€ Deployment Instructions

  1. Create a virtual environment:

    python3 -m venv venv
    source venv/bin/activate
  2. Install dependencies:

    pip install -r requirements.txt
  3. Configure environment variables:

    cp .env.example .env
    # Fill in your OpenAI API key and other necessary variables:
    OPENAI_API_KEY=<your_openai_api_key>
  4. Run the application:

    uvicorn main:app --host 0.0.0.0 --port 8000

πŸ“œ API Documentation

πŸ” Endpoints

  • /models: (GET) Returns a list of available OpenAI models.
  • /generate: (POST) Generates text using a chosen OpenAI model.
  • /translate: (POST) Translates text between languages.
  • /question: (POST) Answers a question using an OpenAI model.
  • /code: (POST) Generates code in a specified programming language.

πŸ”’ Authentication

The API uses basic authentication. You need to provide your OpenAI API key in the request header:

Authorization: Bearer <your_openai_api_key>

πŸ“ Examples

Text Generation:

curl -X POST http://localhost:8000/generate \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_openai_api_key>" \
  -d '{"model": "text-davinci-003", "prompt": "Write a short story about a cat who goes on an adventure.", "temperature": 0.7}'

Translation:

curl -X POST http://localhost:8000/translate \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_openai_api_key>" \
  -d '{"source_language": "en", "target_language": "fr", "text": "Hello, world!"}' 

Question Answering:

curl -X POST http://localhost:8000/question \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_openai_api_key>" \
  -d '{"question": "What is the capital of France?"}'

Code Generation:

curl -X POST http://localhost:8000/code \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_openai_api_key>" \
  -d '{"language": "python", "prompt": "Write a function that prints Hello World."}'

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

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