AI Chat rolling rolling updates

AI Chat rolling rolling updates…

I have just arranged a machine in Proxmox with Ubuntu server that will be the base for this project, I gave it about 8 GB RAM and 100 GB Storage, that should be enough for this project.
Since I have limited resources for this project, I will use a technique that will make sure that there will be a maximum of three models that are active at the same time, and then rotate so that the three are replaced all the time. I think that 10 “participants” is enough. Each model will be assigned different “personalities” that all have different interests, strengths and weaknesses with different guidelines for opinions and values.

First of all, of course i run updates

Now it’s time to install our AI, in this case Ollama.

Now it’s time to load several different models for Ollama.

Since it would take a while to load all the models as I have limited my 1GB line to 100Mbit on the server, I left it overnight but noticed that something went wrong when downloading the last models, I got this error:

It could be due to a problem with the server at Ollama or something else temporary, so I decided to initially settle for the models I already have..

Now it’s time to create a venv (Virtual Environment for Python) and install some dependencies for Python. 🐍

Since it is a new installation, I first needed to install the venv itself:

To build my venv I run:

To build my venv I run:

The virtual environment allows you to install packages for dependencies only in that environment, this is smart for several reasons.
It is important not to forget to always run source venv/bin/activate before working with the bot, so that everything installs correctly!

Now it’s time to get started with the fun.
I’m going to create these files:

.env
main.py
agents.py
agent_manager.py
chat_handler.py

and we’ll start with .env:


Add bot token and channel (get the channel ID from Discord’s developer UI):

Now i we crate agents.py It is in this file that i determine the “personalities” for the models. I assign them their roles. Here we can add different things but it is best to keep it simple.

The next step is to create the file agent_manager.py which is where, among other things, my function for rotating the models is located.

Now the file chat_handler.py is created, which as you probably understand,it handles the things related to the chat itself.

Now it’s time to write the code for main.py which is the most important part, this is where I create the function so they can interact and discuss with each other.

Now all we have to do is start Ollama as a system service and then run main.py , but first we also need to create a bot in the Discord developer portal and give it the right permissions and then invite it to the server and channel. That’s it, it jumps into the channel but I notice that nothing more than that happens so I start troubleshooting and realize that I have way too little RAM allocated to run so many models at once, so I rewrite agents.py to:

and try loading a small model locally and test, at first it doesn’t get any contact with Ollama but then it starts but is very sluggish so I simply have to allocate more ram and then rewrite a bit so that only two – three models are used..

When I restarted the Ollama service, it spat out some things about not being able to communicate with Ollama, etc. but after restarting Ollama, I was now able to write in the chat on my own, but it just got an empty message. I will troubleshoot this and come back with a solution when I have found the error.

Wow, I finally got it working, as I thought it was all about resources and that the server was too weak and lacks a GPU. I tested instead on a regular computer with i7 processors, 32 GB RAM and a GTX 1060 with 6GB, and now it works as it should, at first I tested only with one model to see that it works, now I’m testing with two. I also changed a little in the code for main.py so that the models actually talk to each other and debate and respond to each other’s posts.

This is the updated main.py

I changed the starting subject and then one of the models replied with a long text of 4000 characters. I had forgotten that Discord has a limit of 2000 characters so I had to make some changes again.

This code is added just before edit and/or send:

Finally..

Here we have now got everything working as intended, in this case there are only two models at the moment but it is easy to add more models and “personalities”. To take it a step further I am thinking of later adding so that it is not just a single starting topic but a list of topics that are randomised, it is not a gigantic project but I feel that I have now achieved the goal of the lab.
You can find all the finished files and documentation on my GitHub.