Skip to content

rarcifa/ai-qa-service

Repository files navigation

AI QA Service

Version Badge Version Badge Version Badge

Overview

The AI QA Service is a Node.js TypeScript application designed to host QA services utilizing the LangChain library and OpenAI integrations. This document provides detailed instructions on setting up, configuring, and running the service, including Docker containerization and security key generation.

Diagrame

Table of Contents

  1. Prerequisites
  2. Setting Up the Project
  3. Running the Service
  4. Docker Setup
  5. Generating Security Keys
  6. Environment Variables
  7. Local Document Context
  8. Endpoints
  9. VS Code Configuration
  10. Testing
  11. Links of Interest

Prerequisites

  • Node.js v18.0.0 or later
  • npm v9.4.0 or later
  • Docker (for containerization)
  • TypeScript knowledge (for development)
  • C++ build tools for native module compilation. This is required for the hnswlib-node module. Depending on your operating system, the installation steps may vary:
    • For Windows, install the Windows Build Tools via npm:
      npm install --global windows-build-tools
    • For macOS, you need Xcode Command Line Tools. You can install them by running:
      xcode-select --install
    • For Linux distributions, you need to install build-essential and other necessary development tools. For example, on Ubuntu or Debian-based systems, run:
      sudo apt-get install build-essential

Setting Up the Project

  1. Clone the repository to your local machine.

  2. Navigate to the project directory.

  3. Install dependencies:

    npm install

Running the Service

  1. Compile TypeScript files to JavaScript:

    npm run build
  2. Run the service in development mode:

    npm run dev

Docker

  1. Build the Docker image using the provided Dockerfile:

    docker build -f .docker/build.dockerfile -t ai-qa-service .
  2. Run the service using Docker:

    docker run -it --init \
      -e DB_HOST=your_db_host \
      -e DB_NAME=your_db_name \
      -e DB_USERNAME=your_db_username \
      -e DB_PASSWORD=your_db_password \
      -e NODE_ENV=your_node_env \
      -e OPENAI_API_KEY=your_openai_api_key \
      -e QA_READ_API_KEY=your_qa_read_api_key \
      -e QA_READ_API_SECRET=your_qa_read_api_secret \
      -e QA_WRITE_API_KEY=your_qa_write_api_key \
      -e QA_WRITE_API_SECRET=your_qa_write_api_secret \
      ai-qa-service

Generating Security Keys

The security module in the application provides functions for generating secure API keys and secrets. It uses cryptographic functions for enhanced security.

  1. To generate an API key:

    const apiKey = security.generateApiKey();
  2. To generate an API secret for a given key:

    const apiSecret = security.generateApiSecret('your-key');

Environment Variables

Set the following environment variables in a .env file:

  • DB_HOST, DB_NAME, DB_USERNAME, DB_PASSWORD for database configuration.
  • NODE_ENV for setting the environment (development, production, etc.).
  • OPENAI_API_KEY for OpenAI integration.
  • QA_READ_API_KEY, QA_READ_API_SECRET, QA_WRITE_API_KEY, QA_WRITE_API_SECRET for qa service authentication. These keys can be generated with the previous functions (e.g. apiKey, apiSecret).

Local Document Context

To provide contextual information to the LangChain library, you can place .txt or .json files in the src/integrations/docs folder. The content of these files will be used to create local vectors for enhanced qa responses.

  • Utilize the createLoader function in LangChain to load these documents:

    createLoader: (): DirectoryLoader => {
      return new DirectoryLoader('./src/integrations/docs', {
        '.json': (path) => new JSONLoader(path),
        '.txt': (path) => new TextLoader(path),
      });
    };

Endpoints

The service exposes various endpoints for qa interactions:

  1. Health Check:

    GET /healthcheck
  2. Generate Query:

    POST /api/v1/qa-service/generate/query
  • Body example for POST request:

    {
      "query": "Help me to get started with the cronos chain..."
    }

VS Code Configuration

For auto-formatting in VS Code, add the following settings to .vscode/settings.json:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "prettier.printWidth": 120
}

Testing

Run the test suite with the following command:

npm run test

Links of interest

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published