npm

quantumx

1.0.7 • Public • Published

QuantumX

QuantumX is a powerful Node.js package for interacting with QuantumX API, providing you with the ability to generate language-based responses for complex queries.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • Node.js 14.0.0 or later
  • npm 7.0.0 or later

Installation

To use QuantumX, you must first install the package. Use the following command to do this:

npm install quantumx

Initialization

After you've installed QuantumX, you need to initialize it with your API key before making any requests. Here's how to do it:

For CommonJS (CJS):

const quantumx = require("quantumx");

quantumx.initializeConfig({ apiKey: "your-api-key" });

For ES6 Modules (ESM):

import quantumx from "quantumx";

quantumx.initializeConfig({ apiKey: "your-api-key" });

Replace 'your-api-key' with your actual API key.

QuantumX L3

You can use the llmV3 function to make requests to the API. This function expects an options object as an argument. This object must have the following property:

  • q: The query you want to send to the API.

In addition, it can optionally have these properties:

  • group_id: Used to create a session for a conversation. Allows the API to keep track of the context and provide relevant responses for follow-up conversation.
  • followUp: Indicates whether you want to have a follow-up conversation. Set it to 0 for no follow-up, and 1 for follow-up. If you set it to 1, you must also provide a group_id.
  • limit: Sets the maximum length of the response. Set it to 0 to let the system automatically calculate the limit.
  • regenerate_id: Allows you to regenerate the last response from a session.
  • temperature: A value between 0 and 1.0 that controls the randomness of the response generation. Higher values (closer to 1) make the output more random, while lower values (closer to 0) make it more deterministic. The default value is 0.7.
  • timeout: Sets the maximum timeout for fetching the response from the API, in milliseconds.
  • model: The language model you want to use for generating the response.

Making a Basic Request

Here's a basic example of making a request without any optional parameters:

try {
  const response = await quantumx.llmV3({ q: "How you can help me?" });
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

In this example, llmV3 will use default values for all optional parameters.

Using Optional Parameters

You can provide any optional parameters you want in the options object. Here are examples for each optional parameter:

group_id and followUp:

try {
  const options = {
    q: "How you can help me?",
    group_id: "my-group-id",
    followUp: 1,
  };
  const response = await quantumx.llmV3(options);
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

limit:

try {
  const options = {
    q: "How you can help me?",
    limit: 100,
  };
  const response = await quantumx.llmV3(options);
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

regenerate_id:

try {
  const options = {
    q: "How you can help me?",
    regenerate_id: "my-regenerate-id",
  };
  const response = await quantumx.llmV3(options);
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

temperature:

try {
  const options = {
    q: "How you can help me?",
    temperature: 0.7,
  };
  const response = await quantumx.llmV3(options);
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

timeout:

try {
  const options = {
    q: "How you can help me?",
    timeout: 5000, // 5 seconds
  };
  const response = await quantumx.llmV3(options);
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

Using the Translate Latest Endpoint

QuantumX provides a translateLatest function that you can use to translate text into a different language. This function expects an options object with the following properties:

  • text: The original text that you want to translate. This is a required property.
  • target_language: Specify a language code for the desired target language. This is not a requirement and by default, the language is set to English ("en"). You can retrieve a list of supported languages using the supportedLanguage API.
  • timeout: The maximum timeout for fetching the response from the API, in milliseconds. This is optional, and the default is 120000 (120 seconds).

Here is an example of using this function:

try {
  const response = await quantumx.translateLatest({
    text: "Hello, I am QuantumX",
    target_language: "en",
  });
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

In this example, if "Hello, I am QuantumX" is successfully translated into English, the translated text will be logged to the console. If an error occurs, the error message will be logged to the console.

Supported Language API (translateLatest):

QuantumX provides a supportedLanguage function which you can use to get a list of supported languages. These are the languages you can pass as the target_language when using the translateLatest function.

The supportedLanguage function is a GET API and does not require any parameters. Here is an example of how to use it:

try {
  const response = await quantumx.supportedLanguage();
  console.log(response);
} catch (error) {
  console.error("An error occurred:", error.message);
}

In this example, if the request is successful, the list of supported languages will be logged to the console. If an error occurs, the error message will be logged to the console. Remember that you should always handle errors in your actual application.

Documentation

For more detailed information about QuantumX, check out the full documentation.

Error Handling

You should always handle any potential errors when making requests. If the APIs function throws an error, it will always be an instance of Error and the error message will provide details about what went wrong. This might be a message from the API itself or a message about a network error.

The examples above show basic error handling with a try-catch block. This will catch any errors thrown by APIs and log the error message to the console. In a real application, you should adjust this to handle errors in a way that makes sense for your use case.

Package Sidebar

Install

npm i quantumx

Weekly Downloads

0

Version

1.0.7

License

MIT

Unpacked Size

14.3 kB

Total Files

9

Last publish

Collaborators

  • quantumx