- π Overview
- π¦ Features
- π Structure
- π» Installation
- ποΈ Usage
- π Hosting
- π License
- π Authors
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.
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. |
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
- Python 3.9+
pip
package manager- PostgreSQL (optional)
-
Clone the repository:
git clone https://github.com/coslynx/OpenAI-Python-Wrapper.git cd OpenAI-Python-Wrapper
-
Install dependencies:
pip install -r requirements.txt
-
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
- Create a
-
(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.
- Start the development server:
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
-
Install the Heroku CLI:
npm install -g heroku
-
Login to Heroku:
heroku login
-
Create a new Heroku app:
heroku create OpenAI-Python-Wrapper-production
-
Set up environment variables:
heroku config:set OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE heroku config:set DATABASE_URL=your_database_url_here
-
Deploy the code:
git push heroku main
-
Run database migrations (if applicable):
heroku run python manage.py migrate
OPENAI_API_KEY
: Your OpenAI API key.DATABASE_URL
: Connection string for your PostgreSQL database (if applicable).
-
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}!\")" }
This Minimum Viable Product (MVP) is licensed under the GNU AGPLv3 license.
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
For any questions or concerns regarding this AI-generated MVP, please contact CosLynx at:
- Website: CosLynx.com
- Twitter: @CosLynxAI
Create Your Custom MVP in Minutes With CosLynxAI!