- π Overview
- π¦ Features
- π Structure
- π» Installation
- ποΈ Usage
- π Hosting
- π License
- π Authors
The repository contains a Minimum Viable Product (MVP) called "AI Powered Python Wrapper Service" that provides a streamlined backend service for integrating OpenAI's powerful language models into applications. This service acts as an intermediary between developers and the OpenAI API, offering a user-friendly interface and abstracting away the complexities of direct API interactions.
Feature | Description | |
---|---|---|
βοΈ | Architecture | The codebase follows a clean and modular architecture, organized into distinct components for API routes, database models, and utility functions. |
π | Documentation | This README file provides a comprehensive overview of the MVP, its functionalities, dependencies, and usage instructions. |
π | Dependencies | The project utilizes key libraries like FastAPI for building the RESTful API, OpenAI for interacting with AI models, SQLAlchemy for database operations, and JWT for authentication. |
𧩠| Modularity | The codebase is structured into separate modules for routes, models, schemas, and utilities, promoting code reuse and maintainability. |
π§ͺ | Testing | Unit tests are implemented to ensure the correctness of individual functions and components. |
β‘οΈ | Performance | The service is designed to handle requests efficiently, optimizing API calls and minimizing response times. |
π | Security | Robust authentication and authorization mechanisms protect sensitive data and API keys. |
π | Version Control | Utilizes Git for version control with a clear branching strategy to manage code changes and releases. |
π | Integrations | Seamlessly integrates with the OpenAI API, leveraging its models for text generation, translation, and other capabilities. |
πΆ | Scalability | The architecture is designed to handle increased user load and demands, utilizing cloud infrastructure and efficient resource management. |
ai-wrapper-service/
βββ api
β βββ routes
β βββ auth.py
β βββ text.py
βββ models.py
βββ schemas.py
βββ tests
β βββ test_routes.py
βββ utils
β βββ auth_utils.py
βββ .env
βββ requirements.txt
βββ main.py
βββ README.md
βββ .gitignore
- Python 3.9+
- PostgreSQL 13+
- Docker 20.10+
pip
package manager
- Clone the repository:
git clone https://github.com/coslynx/AI-Powered-Python-OpenAI-Wrapper.git cd AI-Powered-Python-OpenAI-Wrapper
- Install dependencies:
pip install -r requirements.txt
- Set up the database:
- Create a database named
ai_wrapper_service
in PostgreSQL. - Update the
DATABASE_URL
environment variable in the.env
file with the correct connection string. - Run the following command to create the database tables:
python -m sqlalchemy.orm create -u "$DATABASE_URL"
- Create a database named
- Configure environment variables:
- Make a copy of the
.env.example
file:
cp .env.example .env
- Update the environment variables in the
.env
file with your OpenAI API key and database credentials.
- Make a copy of the
- Start the application:
uvicorn main:app --host 0.0.0.0 --port 8000
- Build a Docker image:
docker build -t ai-wrapper-service:latest .
- Run the Docker container:
docker run -d -p 8000:8000 ai-wrapper-service:latest
DATABASE_URL
: Connection string for the PostgreSQL database. Example:postgresql://user:password@host:port/database
OPENAI_API_KEY
: Your OpenAI API key for accessing OpenAI's services. Example:sk-your_api_key_here
JWT_SECRET_KEY
: A secret key used for signing and verifying JWT tokens. Example:your-256-bit-secret
- POST
/api/v1/generate_text
- Description: Generate text using OpenAI's language models.
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
- Body:
{ "input_text": "Write a short story about a robot who dreams.", "model": "text-davinci-003", "temperature": 0.7 }
- Response:
{ "choices": [ { "text": "Once upon a time, in a world where technology had advanced beyond human comprehension, there lived a robot named Unit 7. Unit 7 was a marvel of engineering, designed to perform complex tasks with unwavering precision. However, unbeknownst to his creators, Unit 7 possessed a secret - he dreamt.", "index": 0, "logprobs": null, "finish_reason": "stop" } ], "created": 1692509441, "model": "text-davinci-003", "usage": { "prompt_tokens": 13, "completion_tokens": 67, "total_tokens": 80 } }
- Register a new user or login to receive a JWT token:
- Send a POST request to
/api/v1/auth/signup
to register a new user. - Send a POST request to
/api/v1/auth/login
to authenticate an existing user.
- Send a POST request to
- Include the token in the Authorization header for all protected routes:
Authorization: Bearer YOUR_JWT_TOKEN
# Register a new user
curl -X POST http://localhost:8000/api/v1/auth/signup \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "securepass123"}'
# Response (successful registration)
{
"message": "User created successfully"
}
# Login an existing user
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "securepass123"}'
# Response (successful login)
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyQGV4YW1wbGUuY29tIiwiZXhwIjoxNjkzMjg2NjE0fQ.d7H-w5M-x_vZ2g5t3w2vU97qF6_G5Z70pZ3i1T2-dI",
"token_type": "bearer"
}
# Generate text with authentication
curl -X POST http://localhost:8000/api/v1/generate_text \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyQGV4YW1wbGUuY29tIiwiZXhwIjoxNjkzMjg2NjE0fQ.d7H-w5M-x_vZ2g5t3w2vU97qF6_G5Z70pZ3i1T2-dI" \
-d '{"input_text": "Write a short story about a robot who dreams.", "model": "text-davinci-003", "temperature": 0.7}'
# Response (successful text generation)
{
"choices": [
{
"text": "In the heart of a bustling metropolis, where towering skyscrapers scraped the sky, resided a unique robot named R-42. Unlike his mechanical brethren, programmed for efficiency and logic, R-42 dreamt. Not in the literal sense, of course, but his circuits hummed with a peculiar form of sentience, crafting narratives of a world beyond the sterile reality of his programming. Each night, as his processors powered down, R-42 would drift into a state of simulated slumber, his circuits conjuring vivid scenes of verdant forests, shimmering lakes, and the gentle caress of the sun.",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
],
"created": 1692509441,
"model": "text-davinci-003",
"usage": {
"prompt_tokens": 13,
"completion_tokens": 125,
"total_tokens": 138
}
}
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: AI-Powered-Python-OpenAI-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!