Wie man einen lokalen KI Bot erstellt und ihn mit privaten Daten füttert - How to create a local AI bot and feed it with private data

in Programming & Devlast month (edited)

Hallo zusammen (english see below),

Die KI kann einem mittlerweile ziemlich gut helfen Dinge zu finden oder Probleme zu lösen. Die allgemeinen Large Language Modells, wie ChatGPT oder Perplexity, verstehen inzwischen recht gut, was wir wollen. Aber sie sind nicht auf bestimmte Daten trainiert. OpenAI bietet zwar mit den GPTs Modelle an, die sich mit Daten trainieren lassen. Hier habe ich z.B. beschrieben, wie man eigene Daten hochlädt und dann die KI über die API Schnittstelle mit eine Python Script befragt.

grafik.png
(Erstellt mit Microsofts Copiloten)

Das Problem:

Möchte man aber eine KI zu Daten fragen, die man selber erstellt hat (Know How Sammlung, Steuerdaten, private Tagebücher,...), funktioniert das so nicht. Man möchte schließlich nicht diese Daten ins Internet stellen.
Außerdem kostet diese Lösung in der Regel Geld.

Die Lösung:

Man läßt die KI lokal laufen. Wie das geht beschreibe ich im Folgenden anhand des Beispiels von GPT4All:

Installation von GPT4All

Voraussetzung: Der PC muss mindestens 8 GB RAM und genügend Platz auf der Festplatte haben (je nach LLM über 40 GB)
Das Tool (192 MB) kann hier für Windows, OSX oder Ubuntu herunter geladen werden: https://gpt4all.io/index.html

Nach der Installation von GPT4ALL habe ich ein paar LLMs auf meine Festplatte runter geladen:

grafik.png
Das geht über das Downloadmenue:

grafik.png
(Ich glaube, man kann sie aber auch "normal" herunter laden und in das Verzeichnis legen.)

Man sollte dabei den freien Platz seiner Festplatte im Auge behalten.
Mit Nous Hermes 2 Mistral DPO (4 GB) habe ich bisher recht gute Erfahrung gemacht.
Nun kann man schon los chatten. Aber die Ergebnisse sind ja noch sehr allgemein.

Mit eigenen Daten füttern

Um das Tool mit eigenen Daten zu füttern habe ich einen Ordner mit rudimentären Trainingsdaten zu meinen Hühnern erstellt:

grafik.png

Diese müssen nun eingebunden werden. Das geht über das Zahnradsymbol rechts oben und dann "LocalDocs" auswählen:

Beim ersten Mal, wenn man auf LocalDocs klickt, muss man noch ein Modell namens "SBert" runter laden. Dieses ist nötig um die lokalen Daten zu indizieren:

grafik.png

Danach kann man seine Trainingsdaten hochladen. Dazu gibt man den Namen des Ordners an, in dem die *.txt, *.md, *.rst oder *.pdf Daten liegen:

grafik.png
Wichtig ist, dass die Trainingsdaten auch für das LLM aktiviert sind:

grafik.png
Achtung, das Programm braucht etwas Zeit um das zu initialisieren (ein paar Minuten). Es lohnt sich den Systemmonitor anzuschalten.
Ich musste ein paar mal GPT4All durchstarten, damit es bei mir gezogen hat. Aber nun klappt es:

grafik.png
grafik.png
(So ganz überzeugt mich die k"I" aber noch nicht ;-) )

Weitere Doku dazu siehe auch: https://docs.gpt4all.io/gpt4all_chat.html

Als nächstes möchte ich via API und einem Python script auf meinen Chatbot zugreifen.
Also, stay tuned,

Achim Mertens


English

Hello everyone,

AI can now help you find or solve things pretty well. The general large language models, such as ChatGPT or Perplexity, now understand what we want quite well. But they are not trained on specific data. With GPTs, OpenAI offers models that can be trained with data. Here I described, for example, how to upload your own data and then query the AI via the API interface with a Python script.

The problem:

But if you want to ask an AI about data that you have created yourself (know-how collection, tax data, private diaries,...), it doesn't work that way. After all, you don't want to put this data on the Internet.

The solution:

You let the AI run locally. I will describe how this works below using the example of GPT4All:

Installing GPT4All

Requirement: The PC must have at least 8 GB RAM and enough space on the hard drive (depending on the LLM over 40 GB)
The tool (192 MB) can be downloaded here for Windows, OSX or Ubuntu: https://gpt4all.io/index.html

After the installation, I downloaded a few LLMs onto my hard drive:

grafik.png
This can be done via the download menu:

grafik.png

You should keep an eye on the free space on your hard drive.
I've had pretty good experiences with Nous Hermes 2 Mistral DPO (4 GB) so far.
Now you can start chatting. But the results are still very general.

Feed with your own data

In order to feed the tool with my own data, I created a folder with my rudimentary training data for my chickens:

grafik.png

These now have to be integrated. This can be done using the gear symbol at the top right and then selecting “LocalDocs”:

The first time you click on LocalDocs, you have to download a model called "SBert". This is necessary to index the local data:

grafik.png

You can then upload your training data. To do this, enter the name of the folder in which the *.txt, *.md, *.rst or *.pdf data is located:

grafik.png
It is important that the training data is also activated for the LLM:

grafik.png
Attention, the program needs some time to initialize (a few minutes). It is worth turning on the system monitor.
I had to start GPT4All a few times to get it to work for me. But now it works:

grafik.png

grafik.png
(But this AI isn't really smart)

For further documentation see also: https://docs.gpt4all.io/gpt4all_chat.html

Next I would like to access my chatbot via API and a Python script.
So, stay tuned,

Achim Mertens

Sort:  

I'm not sure I even got half of what you did, but it surely looks super interesting and cool!

Curated with @arc7icwolf.byte for the #LeartToCode Community

Cool, das möchte ich auch mal testen, die KI mit eigenen Dokumenten zu trainieren.

Really?
Thai is very much explanatory and easy
Thanks for sharing with us
I’m surely going to give it a try

Thank you so much for this well detailed explanation. So simple to also understand

You must be a computer guru for you to be able to code and decode all these figures 😀

These statistical method keep me updated. Kudos to you