Deploy an AI Text and Image Chatbot from Scratch: A Complete Step-by-Step Guide
This guide walks beginners through deploying an AI chatbot that can handle both text and images. It explains the four core layers of the system, then breaks the setup into clear stages: preparing a dedicated account and runtime environment, installing the protocol-side program, establishing a WebSocket connection, connecting a model and writing the business logic, and finally tuning performance and handling operations. The goal is to get a working end-to-end pipeline running first, then improve stability and output quality. Readers will find configuration examples, a minimal working code sample, and a troubleshooting order for common failures.
1. Why Deployment Is the Real Bottleneck
Over the past couple of years, conversational agents built on large language models have moved from research labs into the daily workflows of individual developers. Many open-source or partially open-source agent frameworks are designed to push capability limits, but they assume the user already has solid backend experience: process management, messaging protocols, asynchronous frameworks, container orchestration, and the ability to read obscure error stacks. As a result, a large number of valuable projects get stuck at the very first step—installation—and only a handful of people ever get them running.
Lowering the barrier does not mean stripping out features. It means layering the complexity: splitting “getting it to run” and “running it well” into two separate stages. This article follows that approach. First, close the loop on the full pipeline; then discuss stability and quality optimization.
2. Overall Architecture: What Each Component Does
A working text-and-image chatbot usually consists of four layers:
- Account layer: a dedicated instant messaging account for the bot, kept physically separate from your personal account.
- Protocol access layer: maintains the login session as an unofficial client and converts platform messages into standardized JSON events pushed outward. Programs of this kind are generally referred to as OneBot-style protocol implementations, commonly available as a desktop client version, a console version, and a container version.
- Business logic layer: receives events, calls the model, assembles replies, and handles images and multi-part messages.
- Model service layer: either an externally exposed inference endpoint or a locally deployed open-source weight model, called through a unified HTTP interface.
The data flow is clear and one-directional: platform → protocol端 → WebSocket server → business program → model API → back along the same path.
3. Step Zero: Prepare a Dedicated Account and Runtime Environment
Using a freshly registered account is strongly recommended, for three reasons: first, it prevents the bot’s automatic replies from polluting your private conversations; second, a new account carries no historical risk-control flags, so login success rates are higher; third, it makes clean separation easy when you later run multiple instances in parallel.
For the environment, Windows 10 64-bit or above, macOS, or a mainstream Linux distribution all work. At least 8GB of RAM is recommended; if you choose local inference, 16GB or more is advisable, and a machine with a dedicated GPU should be prioritized. Also keep a host machine online long-term, because once the protocol-side process exits, the bot goes offline.
4. Step One: Install the Protocol-Side Program
Using the desktop graphical version as an example, the flow is usually as follows:
- Go to the releases page from the project homepage on the code hosting platform, and choose the installer with an
msiorexesuffix; - Double-click to install, and complete the runtime library dependencies through the wizard;
- Once installed, launch it and enter the account management screen.
The reason for choosing the graphical version is practical: visual configuration reduces errors, it supports running multiple accounts within the same program, and the log panel is intuitive. If you are comfortable with the command line, containerized deployment is also an option, but troubleshooting costs are higher, so it is not recommended as a beginner’s first choice.
5. Step Two: Establish a Two-Way Communication Channel
This is the most error-prone step in the whole process, and it requires a precise understanding of two concepts.
WebSocket server mode: the protocol side actively listens on a port, and the business program connects in as a client. Key configuration points: enable the server switch, set the port to 3001 (the default for most frameworks), and confirm the firewall allows it through.
WebSocket reverse connection mode: the business program listens on a port, and the protocol side connects in actively. This suits scenarios where the business side runs inside a container and the protocol side runs on the host machine.
Example configuration snippet (forward mode):
{"network": {"websocketServers": [{ "enable": true, "host": "127.0.0.1", "port": 3001 }]}}
If the interface offers “advanced settings,” it is advisable to enable heartbeat keep-alive and automatic reconnection; these two directly determine long-term online stability. After saving, return to the list and click start, then log in by scanning the QR code or using an account and password. When the log shows that time synchronization is complete, the handshake has succeeded.
6. Step Three: Connect the Model and Write the Business Logic
Once you receive events, the business program only needs to do three things: filter, call, and reply. A minimal working implementation is as follows:
import json, requestsfrom websocket import create_connectionws = create_connection("ws://127.0.0.1:3001")def send(group_id, text):ws.send(json.dumps({"action": "send_group_msg","params": {"group_id": group_id, "message": [{"type": "text", "data": {"text": text}}]}}))ws.recv()for raw in ws:ev = json.loads(raw)if ev.get("post_type") != "message" or ev.get("message_type") != "group":continueprompt = ev["raw_message"].strip()reply = requests.post("http://127.0.0.1:8000/v1/chat/completions",json={"messages": [{"role": "user", "content": prompt}]}).json()send(ev["group_id"], reply["choices"][0]["message"]["content"])
Engineering details to keep in mind: group messages require handling rate limits; long text should be sent in segments; image messages use the image type with an accessible URL or local path; and conversation context must be maintained yourself, keyed by user ID.
7. Step Four: Tune Quality and Handle Operations
On the prompt side, clearly defining the role, output format, and refusal boundaries is far more effective than piling on adjectives. On the stability side, it is recommended to host the protocol side and the business program as system services, and to add log services plus monitoring and alerting for self-healing on failures; if you use cloud resources, having the container platform handle process supervision, object storage hold media assets, and a message queue smooth out traffic peaks are all mature, industry-standard combinations.
Troubleshooting order for common failures: if it cannot connect, check the port and firewall first; if login fails, switch network environments or use QR code scanning; if replies are empty, inspect the response body from the model API; if images do not display, confirm the resources are reachable over the public internet.
After completing the four steps above, you already have a text-and-image agent that can stay online long-term and keep iterating. The real barrier has never been technical difficulty, but the lack of a guide that explains the order clearly.
