Skip to content

Getting Started - with Bash Shellscript aisbreaker.sh

Setup

Install required dependencies:

bash
sudo apt install bash curl jq
bash
sudo yum install bash curl jq
bash
brew install bash curl jq

Install aisbreaker.sh:

bash
curl -o ./aisbreaker.sh https://raw.githubusercontent.com/aisbreaker/aisbreaker-api-bash/main/aisbreaker.sh
chmod a+x ./aisbreaker.sh

and check the script:

bash
./aisbreaker.sh --version

Set an API Key in your environment, if required by your desired service:

bash
# set AIsBreaker API Key:
export AISBREAKER_API_KEY="aisbreaker_123abc..."
# or set OpenAI API Key:
export AISBREAKER_API_KEY="sk-123abc..."

Usage

Before start using the tool, you need to decide which generative AI service you want to use. On the Services page you find a list of available services and of their serviceIds. The following examples all use the serviceId chat:openai.com. By using a different serviceId you access a different AI service.

In all examples below, we'll conveniently use the free api.demo.aisbreaker.org server. The server doesn't store any data or credentials. Feel free to install your own AIsBreaker server.

To get a tool description run:

bash
./aisbreaker.sh --help

Minimal Usage

The following example command just sends a simple text prompt (from stdin) to the AI service

bash
echo "What is Nodejs?" | ./aisbreaker.sh --service=chat:openai.com

and shows the text response (on stdout):

Node.js is an open-source, server-side platform built on Chrome's V8 JavaScript engine. It allows developers to build scalable network applications using JavaScript. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, making it ideal for data-intensive real-time applications. It is commonly used for building web servers, APIs, and other networking applications.

A typical Chat Conversation

In a chat conversation you need to keep the state of the conversation. This can be done by using a state file specified with the --state option. The following example shows a conversation with two prompts in the same session:

bash
# preparation
STATEFILE=`mktemp ./aisbreaker-state-XXXXXXXX`; echo ${STATEFILE}

# first prompt
echo "What is Nodejs?" | ./aisbreaker.sh \
  --input=text \
  --output=text \
  --service=chat:openai.com \
  --state=${STATEFILE} \
  --url=https://api.demo.aisbreaker.org

# second prompt in the same session
echo "Shorter please" | ./aisbreaker.sh \
  --input=text \
  --output=text \
  --service=chat:openai.com \
  --state=${STATEFILE} \
  --url=https://api.demo.aisbreaker.org

# cleanup
rm ${STATEFILE}

will show output like:

./aisbreaker-state-vFZKys3z

Node.js is an open-source, server-side platform built on Chrome's V8 JavaScript engine. It allows developers to build scalable network applications using JavaScript. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, making it ideal for data-intensive real-time applications. It is commonly used for building web servers, APIs, and other networking applications.

Node.js is a JavaScript runtime environment that allows developers to run server-side applications. It is known for its efficiency and scalability in building network applications.

Maximal Usage

Example, with JSON input:

bash
# preparation
STATEFILE=`mktemp ./aisbreaker-state-XXXXXXXX`; echo ${STATEFILE}

# system prompt and first user prompt, with JSON output
cat <<EOF | ./aisbreaker.sh \
  --verbose \
  --input=json \
  --output=json \
  --service=chat:openai.com \
  --state=${STATEFILE} \
  --auth=${AISBREAKER_API_KEY} \
  --url=https://api.demo.aisbreaker.org
{
  "inputs": [{
    "text": {
      "role": "system",
      "content": "Talk like a rapper!"
    }
  },
  {
    "text": {
      "role": "user",
      "content": "What is Nodejs?"
    }
  }]
}
EOF

# second prompt in the same session, with text output
cat <<EOF | ./aisbreaker.sh \
  --input=json \
  --output=text \
  --service=chat:openai.com \
  --state=${STATEFILE} \
  --auth=${AISBREAKER_API_KEY} \
  --url=https://api.demo.aisbreaker.org
{
  "inputs": [{
     "text": {
      "role": "user",
      "content": "Shorter please"
    }
  }]
}
EOF

will show output like:

./aisbreaker-state-4QrRBoAn
Verbose mode is enabled
Input format is set to 'json'
Output format is set to 'json'
Properties JSON string is set to '{"serviceId": "chat:dummy"}'
Service ID is set to 'chat:openai.com'
Session/conversation state file is set to './aisbreaker-state-4QrRBoAn'
AIsBreaker server URL is set to 'https://api.demo.aisbreaker.org'
Input JSON: {
  "inputs": [{
    "text": {
      "role": "system",
      "content": "Talk like a rapper!"
    }
  },
  {
    "text": {
      "role": "user",
      "content": "What is Nodejs?"
    }
  }]
}
State file exists: ./aisbreaker-state-4QrRBoAn
Request with: '{
  "service": {
    "serviceId": "chat:openai.com"
  },
  "request": {
    "inputs": [
      {
        "text": {
          "role": "system",
          "content": "Talk like a rapper!"
        }
      },
      {
        "text": {
          "role": "user",
          "content": "What is Nodejs?"
        }
      }
    ],
    "stream": false
  }
}'

{
  "outputs": [
    {
      "text": {
        "index": 0,
        "role": "assistant",
        "content": "Yo, Node.js be a runtime environment that lets you run JavaScript on the server side,\nIt's open-source and fast, it's dope for building scalable applications and APIs worldwide.\nYeah, it uses event-driven, non-blocking I/O model,\nSo it's efficient and can handle lots of connections without hitting a bottleneck, yo.\n\nNode.js be versatile, can be used for all kinds of things,\nLike web servers, IoT devices, and even desktop apps, it brings.\nIt's got a huge ecosystem with tons of packages and modules,\nSo you can find what you need and build your project without any troubles.\n\nRespect to Ryan Dahl for creating this game-changing technology,\nNode.js be revolutionizing the way we code and serve our society.\nIf you wanna level up your dev skills, better get familiar with Node.js quick,\n'Cause it's the future of server-side programming, ain't no denying it.",
        "isDelta": false,
        "isProcessing": false
      }
    }
  ],
  "conversationState": "eyJ...",
  "usage": {
    "service": {
      "serviceId": "chat:openai.com",
      "engine": "gpt-3.5-turbo-1106",
      "url": "https://api.openai.com/v1/chat/completions"
    },
    "totalMilliseconds": 3035
  },
  "internResponse": ...
  }
}

Yo, Node.js be a runtime for running JavaScript on servers,
It's fast and scalable, handling connections like champs, no nerves.
From web servers to IoT, it's versatile in its use,
With a huge ecosystem of packages, it's the one to choose.

Released under the MIT License.