Kategorie: IoT

  • Setup your own ChatGPT clone in 5 minutes

    Setup your own ChatGPT clone in 5 minutes

    And another post about A.I… And why this headline? OpenAI’s ChatGPT, Microsoft’s Co-Pilot and Salesforce’s Einstein are just running well! But, are they? And even if you are happy about them, are you willing to pay regular (not cheap) license fees for all of your employees, even if they just use it from time to time? Also, do you really trust Big Tech’s promises about confidentiallity, when it’s about your intellectual property? If you answer all of this by yes, you can stop reading, now. But, in case you would like to know how you easily can run your own A.I. chatbot or you are just curious like me, about how that is done, my article gives you an overview how to do that by utilizing the two amazing tools „Ollama“ and „Open WebUI„.

    chatbot

    Preparation and Requirements

    Theoretically you could even run everything on a laptop, but for sure you would face several issues at least after a while. Better is to have a server with installed docker up and running. Also a reverse proxy, and an URL would make things more smooth, but are not mandatory. As we see later in chapter performance, it would be beneficial if your server has a dedicated graphics card, but also that is not a must.

    Installation and Configuration

    The guys from the „Open WebUI“ project made it extremely easy to get your chatbot running. Basically you just create a new docker-compose.yml file like the one in the example below and start the thing as usual by command „docker compose up -d“. That’s it, no joke!

    services:
      chat:
        container_name: chat
        image: ghcr.io/open-webui/open-webui:ollama
        volumes:
          - ./ollama:/root/.ollama
          - ./open-webui:/app/backend/data
        restart: unless-stopped
        #ports:
        #  - 8080:8080
        networks:
          caddy:
    networks:
      caddy:
        external: true

    As you can see in my example file I customized the network configuration, and also configured my reverse proxy caddy to point access to chat.handtrixxx.com to my new container. As you can see in the following screenshot you can click on „Sign up“ to create a new user account for yourself as Administrator.

    Now, after you logged in, there are just two steps more to do to start your A.I. chats. At first you should go to the admin panel and then at the „Admin settings“ to disable registration for other users to avoid other users just create an account on your instance. Then in the settings at the models tab you will have to download one ore more language models. There are plenty to choose from. An overview is available at: https://ollama.com/library . You are done and as you see it does not have to take more than 5 minutes in case you are a bit experienced in docker and setting up tools in general.

    Costs

    Since everything I introduced and described is based on Open Source software, there are no costs or licensing fees at all. Great, isn’t it? But to say it is completly free is also not completly true, since you have to cover the charges for the server if you do not „have“ one anyway 🙂 .

    Performance

    As mentioned before, a dedicated graphics card would speed up the response times of the chatbot trendemously. By running it only on CPU, like i did in my example, every generation of a response took all the CPU power i have (and I have a lot) for some seconds. So the whole thing feels a bit like the early versions of ChatGPT. That’s no drama, but definitly noticeable.

    Conclusion

    As conclusion i let the openchat language model answer itself to my prompt:

  • Install Docker and Docker Compose

    Install Docker and Docker Compose

    By the utilization of containers, Docker helps us to provide infrastructure and software required for hundereds of projects of any kind.
    The isolated systems created that way are not only more simple to setup and create, but also easier to backup and much more flexible.
    There are thousands of premade Docker images availabe, just waiting to be started by a simple command of you.
    My short article desribes how to install Docker and Docker Compose in a Debian based Linux environment like we have it on a Raspberry Pi or a real server system.
    Docker Compose helps us in so called orchestration of multiple services into easy to maintain .yaml text files.

    Basics

    As mentioned we assume we have a Debian based operating system, like Ubuntu or Raspberry Pi OS installed on our host machine.
    For sure docker is fine on Windows, MacOS or any other Unix based operating system as well, but there the installation and configuration can be slightly different.

    In best case we have a fresh installation of our system with no other additional software installed. That’s not a basic requirement, but keeps things more simple. Additionally we asume we have access to the terminal of our host machine, most likely via ssh session.

    Installation of Docker and Docker Compose

    To ensure we install the latest version we follow the official installation guidline of the docker website.

    1. Install Docker: https://docs.docker.com/engine/install/debian/
    2. Configuration for comfortable usage of Docker: https://docs.docker.com/engine/install/linux-postinstall/
    3. Installation of Docker Compose: https://docs.docker.com/compose/install/

    It looks like much more to do then there actually is. It’s actually not more then a copy & paste operation in 3-4 steps.
    To keep it clean, after installation of the components a reboot is recommended.

    Simple Orchestration with Docker Compose

    Composing with Docker-Composses starts by building up a single file called docker-compose.yml.
    It’s best not to place that file just somewhere but in a structured way, since we could come up with many of them. That’s why it’s called orchestration.
    An example:

    • In directory /opt/ we create a subfolder /opt/docker/ .
    • And there we create more subfolders for our projects or subdomains. Let’s say we make a start with /opt/docker/wordpress/.
    • And in this subfolder we finally place our /opt/docker/wordpress/docker-compose.yml .
    • If we stick with the example of a WordPress installation, there is an example for the content of the docker-compose.yml available at https://hub.docker.com/_/wordpress .

    We extend/change this example by some additional parameters for permament usage and a bit more of comfort in operation. D
    Finally it could look like the following example (consider to keep the tab spaces, since they are mandatory in a .yml file):

    version: '3.1'
    services:
      wordpress-app:
        container_name: wordpress-app
        hostname: wordpress-app
        image: wordpress
        restart: always
        ports:
          - 8080:80
        environment:
          WORDPRESS_DB_HOST: wordpress-db
          WORDPRESS_DB_USER: exampleuser
          WORDPRESS_DB_PASSWORD: examplepass
          WORDPRESS_DB_NAME: exampledb
          TZ: Europe/Berlin
        volumes:
          - ./wordpress:/var/www/html
        logging:
          options:
            max-size: "10m"
            max-file: "3"
    
      wordpress-db:
        container_name: wordpress-db
        hostname: wordpress-db
        image: mysql:5.7
        restart: always
        environment:
          MYSQL_DATABASE: exampledb
          MYSQL_USER: exampleuser
          MYSQL_PASSWORD: examplepass
          MYSQL_RANDOM_ROOT_PASSWORD: '1'      
          TZ: Europe/Berlin
        volumes:
          - ./db:/var/lib/mysql
        logging:
          options:
            max-size: "10m"
            max-file: "3"
    

    Some description of what we did here

    • service, container_name, hostname: just the service name is mandatory, but we set the other 2 parameters for easier access and better overview.
    • image: Fixes the application we want to run. Without additional changes we can use any public image from the Docker Hub https://hub.docker.com/search?q=
    • restart: always means, the container will be restarted in any kind of eventual error.
    • environment: contains any kind of variable passed to the container. Can be slightly different depending on the the type of application we run.
    • volumes: Our persistent data, we want always to keep and maybe consider for backup. By the leading ./ we say it’s a subfolder of the current directory. If that directory doesn’t exist, docker would create it on first start. But it’s better to create those directories in advance to avoid file system permissions issues and similar.
    • logging: Some apps tend to write a lot of operations into the log. By this parameter we limit this to 3 files each with a size of 10MB. Once that storage is completly used, the oldest entry will be overwritten and so on.
    • ports: required in case we do not utilize a reverse proxy. 8080:80 means that the port 80 of the application is made availabe at port 8080 of our host machine. So, if you want to open you wordpress application after start you would open: http://HOST:8080 in your clients browser. By the way: for internal communication between the containers, no additional ports need to be shared. They run in the same hidden networrk, which increases security by making only public what we want to have public.

    Usefull commands

    All the following commands should be started from the directory our docker-compose.ymlfile is stored at. By docker-compose up -d we will start our first application. It will start both defined services/containers, while docker-compose down will shut all of them down again. By docker-compose pull we would provoke to download (pull) the newest version of our images from Docker Hub. To make this update reflected in our environment we just run another docker-compose up -d . The data at the volumes we defined before will not just be overwritten by this. Our wordpress example is a bit special about this since its actually referring to a internal folder of the container, which actually get’s updated, too. Still your custom data stays “alive”. Also because of that, updates eventually could fail, especially if there are major changes in the version of our services. There are different ways to handle this, which I will describe another day.