Skip to content

Demo: JavaScript Code

This demo shows a JavaScript NodeJS application that uses the AIsBreaker API to access AI services.

Other demos: REST API Access (Intro), Chat WebApp (Intro)


Install the AIsBreaker JavaScript/TypeScript library:

npm install aisbreaker-api-js

and import it in your code:

import { api } from "aisbreaker-api-js";


Service Configuration

Define the serviceProps and select the service/serviceId you want to use:

const servicePros = {
    serviceId: "chat:dummy",

    //serviceId: "",

    //serviceId: "",

    //serviceId: "<HF-ACCOUNT>/<HF-MODEL>",

    //serviceId: "aisbreaker:mirror",
    //forward2ServiceProps: {
    //  "serviceId": "chat:echo"

Optionally, provide your own API key for the AI service. If you don't provide a key, a default AIsBreaker API key is used with strict quotas:

const auth = {
    // optionally, set your OpenAI API key:
    //secret: "sk-...",

    // optionally, set your Huggingface API key:
    //secret: "hf_...",

    // optionally, set your AIsBreaker API key:
    //secret: "aisbreaker_...",

Service Initialization

Get the API access via the aisService object:

const aisbreakerServerURL = "";
const aisService = api.AIsBreaker.getInstance().
    getAIsService(aisbreakerServerURL, servicePros, auth);

We use the free server for convenience here. The server doesn't save any data or credentials. Feel free to install your own AIsBreaker server.

Define your Prompt/your Question

const question1 = "What is NodeJS?";
console.log(`***** Question1 ***** ${question1}`);

Get the Response/Answer from the AI Service

const response1 = await aisService.process({
    inputs: [ {
        text: {
            role: "user",
            content: question1,
    } ],
console.log(`***** Answer1 ***** ${response1.outputs[0].text.content}`);

Putting it all together

npm install && npm run start

will show output like:

***** Question1 *****
What is NodeJS?
***** Answer1 *****
Hello, this is the reponse to 'What is NodeJS?' from DummyAssistantService ... To get a useful answer, choose a different service/serviceId ...

Try Variations

  • try different configurations/serviceProps/serviceIds instead of the chat:dummy
  • re-run the example with npm run start

Full Source Code of the Example

... including a longer conversation with 2nd question and 2nd answer ... on GitHub: aisbreaker/aisbreaker-example-simple-chat-node-js/

Open in StackBlitz Web-IDE

More Details

More details on how to access the AIsBreaker API can be found on the Getting Started tutorials in the docs.

But before, you should understand the basic concepts and read the Introduction (AIsBreaker Docs) ...

Released under the MIT License.