Skip to content

arihantparsoya/chatgpt-cloud-service

Repository files navigation

ChatGPT Cloud Service

License Build Status

ChatGPT Cloud Service is a Node.js cloud backend written in TypeScript that allows developers to easily implement the ChatGPT service into their applications for their users. This service handles the authentication token and modifies the requests before passing them to the ChatGPT API.

By using this microservice, developers no longer need to expose their API keys to users, providing a secure way to add ChatGPT functionality to their apps.

Features

  • Securely integrate ChatGPT into your applications
  • Modify and customize requests before sending them to the ChatGPT API
  • Easy-to-use TypeScript interface
  • Deployable as a containerized application
  • Manage user authentication tokens
  • Planned features:
    • Database integration

Prerequisites

Before using the ChatGPT Microservice, make sure you have the following installed:

  • Node.js
  • npm
  • ChatGPT API access token
  • Docker (optional, for containerization)
  • [Optional] Firebase Authentication

Getting Started

Installation

  1. Clone the repository:

    git clone https://github.com/arihantparsoya/chatgpt-cloud-service.git
  2. Navigate to the project directory:

    cd chatgpt-cloud-service
  3. Install the dependencies:

    npm install

Configuration

  1. Open the .env file in the project root directory.

  2. Set your ChatGPT API key in .env file:

    CHATGPT_API_KEY=your-api-key
    

ChatGPT Prompts

To add context and information to your prompts before sending it to ChatGPT, add the additional details as message in the chatController.ts file.

Usage

  1. Start the project:

    npm start
  2. The service will be running at https://localhost:3000.

  3. Make a POST request to https://localhost:3000/chat with the following parameters:

    Example using cURL:

     curl --location 'https://localhost:3000/chat' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Bearer USER_BEARER_TOKEN' \
     --data '{
         "model": "gpt-3.5-turbo",
         "messages": [
             { "role": "system", "content": "you are a helpful assistant" },
             { "role": "assistant", "content": "Hi there! How can I assist you?" },
             { "role": "user", "content": "What is the population of USA" }
         ]
     }'
  4. The microservice will modify the request and forward it to the ChatGPT API. The response from the API will be returned to the user.

Containerization (Docker)

  1. Build the Docker image:

    docker build -t chatgpt-cloud-service .
  2. Run the Docker container:

    docker run -p 3000:3000 chatgpt-cloud-service

    The microservice will be accessible at https://localhost:3000.

[Optional] Firebase Authentication

If you want to add authentication to your APIs using Firebase, you can enable it by setting USE_AUTHENTICATION variable in .env file:

USE_AUTHENTICATION=false

Configure Firebase for authentication by adding your Firebase configurations in serviceAccountKey.json.

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.

Community

Join our Discord community to connect with other developers, ask questions, and get support. Link to Discord Community

License

This project is licensed under the Apache License 2.0. See the LICENSE file for more details.