Git Product home page Git Product logo

ai-qa-service's Introduction

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)

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
  1. 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 .
  1. 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();
  1. 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
  1. 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

ai-qa-service's People

Contributors

rarcifa 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.