Socket
Socket
Sign inDemoInstall

qb-ai-answer-assistant

Package Overview
Dependencies
8
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    qb-ai-answer-assistant

Quickblox AI Answer assistant library


Version published
Weekly downloads
63
increased by110%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

Discord server

QBAIAnswerAssistant

The qb-ai-answer-assistant is a npm package that contains AI Answer Assistant logic. AI Answer Assistant can perform suggestion to answer using Chat Gpt.

Installation

QBAIAnswerAssistant can be installed using Node Package Manager. To include it in your JS based project, follow these command:

npm install qb-ai-answer-assistant

Usage

To use QBAIAnswerAssistant in your project, follow these steps:

  1. Import the QBAIAnswerAssistant module:
import { ChatMessage } from 'qb-ai-core';
import { AIAnswerAssistantSettings, QBAIAnswerAssistant } from 'qb-ai-answer-assistant';
  1. Create an array of ChatMessage objects representing the chat history:
let prompt =  "YOUR_TEXT_TO_ANSWER_ASSIST";

let messages = [
  {role: Role.other, content: "Hello, Bob!"},
  {role: Role.me, content: "Hi, Jim!"},
  {role: Role.me, content: prompt},
]

or

let prompt =  "YOUR_TEXT_TO_ANSWER_ASSIST";

let messages = [
  {role: "assistant", content: "Hello, Bob!"},
  {role: "user", content: "Hi, Jim!"},
  {role: "user", content: prompt},
]
  1. Call the rephrase method to generate translate using an API key:
    const settings: AIAnswerAssistantSettings =
  QBAIAnswerAssistant.createDefaultAIAnswerAssistantSettings();

settings.apiKey = 'YOUR_OPEN_AI_API_KEY';
settings.organization = 'YOUR_ORGANIZATION';//  might be empty
settings.model = AIModel.gpt__3_5__turbo;

return QBAIAnswerAssistant.createAnswer(
  promt,
  messages,
  settings,
);

Alternatively, you can use a QuickBlox user token and a proxy URL for more secure communication:

    const settings: AIAnswerAssistantSettings =
  QBAIAnswerAssistant.createDefaultAIAnswerAssistantSettings();

settings.organization = 'YOUR_ORGANIZATION';//  might be empty
settings.model = AIModel.gpt__3_5__turbo;
settings.token = 'YOUR_QUICKBLOX_USER_SESSION_TOKEN';
settings.serverPath = `https://your-proxy-server-url`;

return QBAIAnswerAssistant.createAnswer(
  promt,
  messages,
  settings,
);

OpenAI

To use the OpenAI API and generate answers, you need to obtain an API key from OpenAI. Follow these steps to get your API key:

  1. Go to the OpenAI website and sign in to your account or create a new one.
  2. Navigate to the API section and sign up for access to the API.
  3. Once approved, you will receive your API key, which you can use to make requests to the OpenAI API.

Proxy Server

Using a proxy server like the QuickBlox AI Assistant Proxy Server offers significant benefits in terms of security and functionality:

Enhanced Security:

  • When making direct requests to the OpenAI API from the client-side, sensitive information like API keys may be exposed. By using a proxy server, the API keys are securely stored on the server-side, reducing the risk of unauthorized access or potential breaches.
  • The proxy server can implement access control mechanisms, ensuring that only authenticated and authorized users with valid QuickBlox user tokens can access the OpenAI API. This adds an extra layer of security to the communication.

Protection of API Keys:

  • Exposing API keys on the client-side could lead to misuse, abuse, or accidental exposure. A proxy server hides these keys from the client, mitigating the risk of API key exposure.
  • Even if an attacker gains access to the client-side code, they cannot directly obtain the API keys, as they are kept confidential on the server.

Rate Limiting and Throttling:

  • The proxy server can enforce rate limiting and throttling to control the number of requests made to the OpenAI API. This helps in complying with API usage policies and prevents excessive usage that might lead to temporary or permanent suspension of API access.

Request Logging and Monitoring:

  • By using a proxy server, requests to the OpenAI API can be logged and monitored for auditing and debugging purposes. This provides insights into API usage patterns and helps detect any suspicious activities.

Flexibility and Customization:

  • The proxy server acts as an intermediary, allowing developers to introduce custom functionalities, such as response caching, request modification, or adding custom headers. These customizations can be implemented without affecting the client-side code.

SSL/TLS Encryption:

  • The proxy server can enforce SSL/TLS encryption for data transmission between the client and the server. This ensures that data remains encrypted and secure during communication.

License

QBAIAnswerAssistant is released under the MIT License.

Contribution

We welcome contributions to improve QBAIAnswerAssistant. If you find any issues or have suggestions, feel free to open an issue or submit a pull request on GitHub. Join our Discord Server: https://discord.gg/GrynPeHMaa

Happy coding! 🚀

FAQs

Last updated on 27 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc