Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/coslynx/openai-python-wrapper

Streamlined API for simplified OpenAI requests, enabling efficient AI integration... Created at https://coslynx.com
https://github.com/coslynx/openai-python-wrapper

ai-integration api-client asynchronous-programming code-generation data-validation database-integration developer-tools devops error-handling fastapi machine-learning model-selection mvp mvp-development openai-library openai-wrapper python python-api software-development text-generation

Last synced: 15 days ago
JSON representation

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

Awesome Lists containing this project

README

        




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

```text
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:**
```bash
git clone https://github.com/coslynx/OpenAI-Python-Wrapper.git
cd OpenAI-Python-Wrapper
```

2. **Install dependencies:**
```bash
pip install -r requirements.txt
```

3. **Set up environment variables:**
- Create a `.env` file in the project root and fill in the required values:
```bash
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:**
```bash
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
```

## ๐ŸŒ Hosting

### ๐Ÿš€ Deployment Instructions

#### Deploying to Heroku

1. Install the Heroku CLI:
```bash
npm install -g heroku
```

2. Login to Heroku:
```bash
heroku login
```

3. Create a new Heroku app:
```bash
heroku create OpenAI-Python-Wrapper-production
```

4. Set up environment variables:
```bash
heroku config:set OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE
heroku config:set DATABASE_URL=your_database_url_here
```

5. Deploy the code:
```bash
git push heroku main
```

6. Run database migrations (if applicable):
```bash
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:
```json
{
"prompt": "Write a short story about a cat.",
"model": "text-davinci-003",
"max_tokens": 100
}
```
- Response:
```json
{
"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:
```json
{
"text": "Hello, world!",
"target_language": "fr"
}
```
- Response:
```json
{
"translation": "Bonjour le monde !"
}
```

- **POST /api/complete_code**
- Description: Completes code snippets using OpenAI's API.
- Body:
```json
{
"prompt": "def greet(name):\n print("
}
```
- Response:
```json
{
"code": "def greet(name):\n print(f\"Hello, {name}!\")"
}
```

## ๐Ÿ“œ License & Attribution

### ๐Ÿ“„ License

This Minimum Viable Product (MVP) is licensed under the [GNU AGPLv3](https://choosealicense.com/licenses/agpl-3.0/) license.

### ๐Ÿค– AI-Generated MVP

This MVP was entirely generated using artificial intelligence through [CosLynx.com](https://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:
- Website: [CosLynx.com](https://coslynx.com)
- Twitter: [@CosLynxAI](https://x.com/CosLynxAI)


๐ŸŒ CosLynx.com


Create Your Custom MVP in Minutes With CosLynxAI!