How to setup AI into Nightbot using Shapes API

You’ve probably gone crazy but yes, it is possible to add AI to Nightbot with an API that is totally free, and that’s the one from Shapes.inc.

Backstory: Shapes.inc is a platform in charge of making fully customizable social AI agents so you are not using a standard AI like ChatGPT, but rather, you are adding to your chat a bot that can perfectly simulate a human or anime character.

Before to Go: :warning: You need to have created a shape in the Shapes.inc dashboard first in order to get API working. You can follow the official Shapes.inc wiki here, there are many advantages and models you can use (Even GPT 4o Mini it’s free), this AI is fully customizable.

  1. According to Shapes Inc API Developer Documentation you can setup a private server using Flask (Python) which the following code:
from flask import Flask, request, jsonify
from openai import OpenAI

# Initialize the OpenAI client for Shapes API
openai = OpenAI(
    api_key="YOUR_API_KEY_HERE",  # Replace with your actual Shapes API key
    base_url="https://api.shapes.inc/v1/"
)

# Create Flask app
app = Flask(__name__)

@app.route('/', methods=['GET'])
def get_response():
    # Read the 'query' parameter from the GET request
    query = request.args.get('query')

    if not query:
        return jsonify({'error': 'No query provided'}), 400

    try:
        # Send prompt to the Shapes API
        response = openai.chat.completions.create(
            model="shapesinc/YOUR_MODEL_USERNAME",  # Replace with your actual model USERNAME (with no @)
            messages=[{"role": "user", "content": query}]
        )

        # Extract the generated message content
        generated_text = response.choices[0].message.content
        return generated_text

    except Exception as e:
        # Return any error as plain text
        return f"Error: {str(e)}", 500

# Run the server on any open port and allow external connections
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

If you are using Pterodactyl or any other hosting service try to add Python Packages into bash installation (if you’re using console then is not needed, just run pip install flask openai.

  1. Setup your Nightbot command
    Now you can go through your chat or Nighbot Console (for better privacy) and add this command:
    !addcom !command_name $(urlfetch http://<your-domain-or-public-ip>:<public-port>/?query=$(query))

As you can see AI works as expected, have fun!

Can you help me?

Since twitch has a character limit you must on the Engine Settings set a limit, I suggest you set it to at least 200 characters (or a single paragraph), and pretend to be a human.

Something like:
{shape} has a maximum of 200 tokens per message.