Coder Social home page Coder Social logo

novelai-proxy-service's Introduction

NovelAI Proxy Service

Description

This NovelAI Proxy Service is a Flask-based application that acts as an intermediary between clients and the NovelAI API. It provides a secure and efficient way to handle requests to NovelAI's image generation service, implementing features such as load balancing, automatic token refresh, and error handling.

Please consume it with NovelAI-API-Unoffical API

Features

  • Secure proxy for NovelAI API requests
  • Load balancing across multiple API endpoints
  • Automatic access token refresh on 403 errors
  • Request queuing and multi-threaded processing
  • Comprehensive logging
  • Environment-based configuration
  • Token-based authentication for incoming requests

Prerequisites

  • Python 3.7+
  • pip (Python package manager)

Project Structure

novelai-proxy-service/
│
├── src/
│   ├── api/
│   │   └── routes.py
│   ├── core/
│   │   ├── config.py
│   │   └── logging.py
│   ├── models/
│   │   └── user.py
│   ├── services/
│   │   ├── api_client.py
│   │   └── worker.py
│   └── utils/
│       └── auth.py
├── logs/
├── .env.example
├── .gitignore
├── requirements.txt
├── setup.py
├── README.md
└── run.py

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/novelai-proxy-service.git
cd novelai-proxy-service
  1. Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate  # On Windows, use venv\Scripts\activate
  1. Install the required packages:
pip install -r requirements.txt
  1. Set up your environment variables by creating a .env file in the root directory:
NOVELAI_USERNAME=your_username
NOVELAI_PASSWORD=your_password
SERVER_TOKENS=token1,token2,token3
NOVEL_TOKEN=your_initial_token  # Optional

Usage

  1. Start the server:
python run.py
  1. The server will start on http://127.0.0.1:5000 by default.
  2. To make a request to the NovelAI API through the proxy, send your request to http://127.0.0.1:5000/ai/generate-image
  3. make sure to include your service authentication token in the Authorization header.

Configuration

  • src/core/config.py: Contains the Config class for managing environment variables and application settings.
  • .env: Store your sensitive information and configuration here.

API Endpoints

  • /ai/generate-image: Proxies requests to NovelAI's image generation API.

Error Handling

  • The service automatically handles 403 errors by refreshing the NovelAI access token.
  • Other errors are logged and appropriate error responses are sent back to the client.

Logging

  • Logs are stored in the logs/ directory.
  • The default log file is app.log.
  • Log rotation is implemented to manage log file sizes.

Security

  • Incoming requests are authenticated using tokens defined in the SERVER_TOKENS environment variable.
  • NovelAI credentials are securely managed through environment variables.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

GNU General Public License v3.0

Disclaimer

This project is not officially affiliated with NovelAI. Use at your own risk and ensure compliance with NovelAI's terms of service.

novelai-proxy-service's People

Contributors

kokosensei avatar

Stargazers

alizoed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.