Accessing Jibber AI (Docker) using JavaScript

To access Jibber AI in Docker from JavaScript, you can use the Fetch API or a HTTP client library such as Axios or Request.

Here are the basic steps to get started:

  • Ensure you have signed up for a Jibber AI license. You will receive an API key that you will need to use to authenticate your requests
  • Ensure you have a Docker container running a Jibber AI container
  • Once you have your API key and Docker container, you can make requests to the API endpoint

NOTE: For production, you should not expose the key by making the call from your front end website as the key could be discovered. These calls would typically be made by a back-end process (E.g. Node)

Here's an example using the Fetch API:

javascript
async function analyzeText(text) {
    const body = {
        "features": {
            "sentiment": true,
            "keyword": true,
            "pii": true,
            "entities": true,
            "summary": true
        },
        "token": "my-license-token-from-jibber-ai",
        "text": text
    }

    // Server name/port will vary depending on how you expose the container
    const response = await fetch('http://my-docker-server-name:5000/analyze', {
        "method": "POST",
        headers: {
          "Content-Type": "application/json"
        },
        body: JSON.stringify(body)
    });
    
    if (response.ok) {
        let responseJson = await response.json();
        return responseJson
    }

    throw new Error(`HTTP error! status: ${response.status}`);
}

analyzeText("My name is Julia Peach and I live in Paris.").then(responseJson => {
    console.log(JSON.stringify(responseJson, null, 2));
});

In the above example, replace http://my-docker-server-name:5000 with your docker host and port. You also need to replace `my-license-token-from-jibber-ai` with your license key.

Once you make the request, the server will send back a response, which you can then handle in the method. In this case, the json method is called on the response object to convert the response to JSON. You can then do whatever you want with the JSON data.

Remember to handle any errors in the catch method in case the request fails.