Giter Club home page Giter Club logo

mini-chat's Introduction

Mini Chat with OpenAI Integration

This project is a small application that allows users to authenticate and make requests to the OpenAI API using NestJS. The application includes user management, OpenAI integration, and security measures to protect user data.

Project Requirements

User Management

  • Registration Endpoint: Allows users to register by providing necessary details (e.g., email, password).
  • Authentication Endpoint: Allows users to log in and receive a JWT token for session management.

OpenAI Integration

  • Question Endpoint: Allows authenticated users to send questions to the OpenAI API and receive responses via Server-Sent Events (SSE). Each question and its corresponding response are stored in the database.
  • Error Handling: Properly handles errors from the OpenAI API.

Security

  • Data Protection: Ensures sensitive user data is stored securely.
  • Authentication & Authorization: Protects endpoints using JWT tokens and ensures proper access control.

Installation and Setup

Prerequisites

  • Node.js
  • yarn
  • Docker (optional, for containerized environments)

Clone the Repository

git clone https://github.com/linc-inc/mini-chat.git
cd mini-chat

Install Dependencies

yarn install

Environment Variables

Create a .env file in the root directory and add the necessary environment variables:

JWT_SECRET=your_jwt_secret
OPENAI_API_KEY=your_openai_api_key

Database Setup

This project uses SQLite for the database.

Running the Application

yarn run start:dev

Accessing the Database

To view and manage your SQLite database, you can use TablePlus or any other SQLite database viewer.

Endpoints Overview

User Management

  • POST /auth/register: Register a new user.
  • POST /auth/login: Authenticate a user.
    • Request Body: { "email": "[email protected]", "password": "password123" }
    • Response: { "access_token": "jwt_token" }

OpenAI Integration

  • POST /openai/question: Send a question to OpenAI and receive the response via Server-Sent Events (SSE).

    • Headers: { "Authorization": "Bearer jwt_token" }
    • Request Body: { "question": "What is NestJS?" }
    • Response: If streaming is chosen, the response will be handled via Server-Sent Events (SSE). Otherwise, the response of this endpoint will be the AI's response directly.
    • The question and its corresponding response will be stored in the database.
  • (Optional) GET /openai/stream: Stream responses to the client's questions in real time via Server-Sent Events (SSE).

    • Headers: { "Authorization": "Bearer jwt_token" }
    • Response: The response from the AI will be streamed back to the client

Security Considerations

  • Password Hashing: Ensure passwords are hashed before storing in the database.
  • JWT Expiry: Implement expiration for JWT tokens to enhance security.

Discussion Points

  • Approach: Be ready to discuss how you approached the project.
  • Tradeoffs: Discuss any tradeoffs made due to time constraints.
  • Next Steps: Be prepared to outline next steps for improving scalability and security.

mini-chat's People

Contributors

santiagoguerra19 avatar allucardster 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.