Saturday, July 27, 2024

The way to Set Up AutoGen Studio with Docker – Be on the Proper Aspect of Change

[ad_1]

Hello and welcome to this tutorial collection on AutoGen Studio. My title is Dirk van Meerveld, and I’ll be your host and information for this three half tutorial collection the place we’ll check out AutoGen Studio.

👉 Go Again to the Full Course: Subsequent Degree Immediate Engineering with AutoGen Studio

AutoGen Studio is an open-source interface that runs on high of AutoGen. This mix will permit us to work with LLMs and provides them expertise (like instruments/capabilities) that they will use and in addition permits us to make use of brokers and even outline multi-agent workflows. Consider it as a multi-agent framework. Some of the superb options is that it will probably write and execute code on the fly to resolve issues!

On high of that AutoGen Studio supplies us with a smooth and easy-to-use interface to outline all of the above and chat with our brokers, a lot of it with out even having to jot down code! This actually is next-level immediate engineering and over the approaching classes, we’ll harness the ability of digital brokers and see them collaborate with one another!

🖨️ Really useful Academy CourseVoice-First Growth: Constructing Chopping-Edge Python Apps Powered By OpenAI Whisper ⭐⭐⭐⭐⭐

On this first half, we’ll give attention to the setup and take a while to correctly get began. When you’re a extra seasoned developer and intimately conversant in a selected matter like Docker, be at liberty to skip forward a bit right here and there, however we’ll cowl all of the bases so that everyone can observe alongside properly. That is particularly in order a lot of AutoGen Studio can be utilized through the interface which makes it extra accessible to non-coders. We are going to depart no man or girl behind!

AutoGen security measures

In an effort to reply extra complicated requests AutoGen will truly write Python code for you and execute this Python code in your native laptop.

For instance, there’s a demo query the place you ask the next query: "Plot a chart of NVDA and TESLA inventory value for 2023. Save the consequence to a file named nvda_tesla.png". AutoGen will remedy this query by writing Python code to get the inventory costs, set up wanted libraries to execute the code, write code for creating the graph in MathPlotLib, and many others… It can then execute this code in your native laptop and return the consequence to you.

The issue happens the place working techniques after all have some type of built-in safety. Usually, the Execution Coverage in your OS will forestall AutoGen (and others) from simply operating random code and scripts in your laptop. And this can be a good factor! One answer could be to loosen up the Execution Coverage in your laptop, however this isn’t actually one of the best thought. Even should you don’t have an Execution Coverage downside in your system, do you actually wish to have any and all AI-generated code operating in your machine with none checks or balances? It’s a bit harmful, to say the least.

Why we gained’t use Anaconda

Many tutorials attempt to take the 100% no-code method, utilizing Anaconda for digital environments and never utilizing an IDE like VS Code altogether in an try to say that ‘You don’t must know any code in any respect’. Then you’ll:

  • Nonetheless have to put in Docker in addition to Anaconda, so as to permit secure code execution inside a Docker container.
  • Set your API key time and again each time you reload.
  • Kind the identical Anaconda instructions time and again.
  • You may be caught with a buggy expertise making an attempt to get it to make use of Docker for secure code execution, inflicting you lots of frustration.

Whereas there may be completely nothing mistaken with Anaconda, it doesn’t take away the necessity for Docker for secure code execution because it doesn’t present any isolation out of your native system. So why don’t we simply use Docker as a substitute of Anaconda AND Docker? This biting the bullet will make this half 1 of the tutorial a bit more durable, however after that, will probably be easy crusing all the way in which! ⛵

Docker to the rescue

Utilizing this method we are able to skip Anaconda altogether as Docker will even be separate from our system-wide Python setting, and now we have only one piece of software program to fret about for each the separate setting and the secure code execution. We are going to use some naked fundamental code within the type of a ‘docker file’ and fundamental instructions, however you may simply copy mine, so no worries! Once more, should you’re already a Docker knowledgeable, be at liberty to only skip forward to the Dockerfile and get began.

Docker makes use of working system-level virtualization to ship software program in packages referred to as containers. Containers are remoted from each other and bundle their very own software program, libraries, and configuration recordsdata. All containers are run by a single working system kernel and are thus extra light-weight than digital machines. Crudely said which means docker will allow us to have a separate container with Linux, Python, and all of the libraries we have to run AutoGen Studio in it, type of like operating a distinct laptop system inside a digital machine.

We are going to use this ‘digital machine’, or Docker container, to run AutoGen Studio inside it, which routinely additionally signifies that any code it generates is executed throughout the container, fixing our code execution coverage issues and security considerations in a single go. Caveat: Theoretically even Docker will not be 100% safe and remoted from the remainder of your system, nevertheless it’s loads higher than simply operating code immediately in your native machine and adequate for non-enterprise use.

Getting Docker put in and operating – WSL2

I’m going to imagine you’re on a Home windows machine. When you’re on a Mac or Linux machine, you’re in luck and may most likely simply run the installer for ‘Docker Desktop’ and be performed with it. Simply head over right here and scroll down to pick out the Docker obtain in your platform. https://docs.docker.com/desktop/ (or Google for the up to date hyperlink).

Persevering with for the Home windows customers now, as they’ve a few further steps to take. Most tutorials will simply inform you to put in Docker and provides no particulars which could depart you’ll a long and hard strategy of determining why it gained’t work in your system. So let’s cowl the pitfalls and ensure we get it proper the primary time!

First, we have to set up WSL2 (Home windows Subsystem for Linux 2) on our system. This can be a Home windows function that enables us to run Linux on our Home windows machine. That is wanted as a result of Docker Desktop for Home windows requires WSL2 to run. (You can too use Hyper-Vas a substitute, however WSL2 is the really helpful means).

(When you already use WSL however must verify in case you have model 2, you may verify your model by coming into the command: wsl -l -v in PowerShell or Home windows Command Immediate.)

You’ll find the main points for putting in WSL2 right here, however principally you do that:

  • Open a PowerShell or Home windows Command Immediate in administrator mode by right-clicking and deciding on “Run as administrator”
  • Run the next command within the terminal: wsl --install
  • Restart your laptop when prompted

It will allow WSL in your Home windows machine and set up a Linux distribution (Ubuntu) in your system. You might must create a Username and Password in your Linux distribution and save them someplace. Extra particulars will be discovered right here or google "Establishing your Linux username and password."

Some issues to verify earlier than we set up Docker Desktop

A fast caveat: If anyplace alongside the way in which you run into issues I haven’t lined right here, you’ll must do some googling to search out out what it means and what must be performed, as I can not put together you for each potential downside you would possibly run into.

The software program growth world generally requires messing round and googling for an hour and even two earlier than you get one thing to work, it’s a part of the sport. That being stated I’ll attempt my greatest to cowl all bases so that you’ll hopefully have a really easy expertise 😀.

We now have a pair extra issues to verify earlier than we are able to set up Docker Desktop. First, we want to ensure the Digital Machine Platform possibility is enabled. That is pretty simple! Simply press the Home windows key or click on within the Home windows search bar and seek for “Flip Home windows options on or off”.

Open this and ensure the “Digital Machine Platform” possibility is checked. If it’s not, verify it and click on OK. You might must restart your laptop after this.

(You don’t need to match the opposite checkboxes with the settings within the picture!)

Subsequent, we have to be sure that Virtualization is enabled in our BIOS. The simplest technique to verify if that is enabled is to open the Home windows Process Supervisor by urgent Ctrl+Alt+Delete and deciding on Process Supervisor. Then click on on the Efficiency tab and click on on CPU on the left-hand aspect. If Virtualization is enabled, you will note “Virtualization: Enabled” within the backside proper data block like this:

If Virtualization will not be enabled, you’ll have to go into your BIOS settings and allow Virtualization. That is the place you’ll have to do some googling and analysis by yourself, as each system has barely completely different keys to get into the BIOS setup menu, and the settings could also be situated in numerous components of the BIOS menu for various producers. I’ll depart you with two hyperlinks to get you began, the primary one describes the final strategy of getting this setting enabled in your BIOS:

Whenever you’ve received that prepared and set as much as go, let’s proceed on.

Putting in Docker Desktop 🚀

Lastly, it’s time! Head over to the Docker Desktop obtain web page right here and obtain the suitable Docker model in your OS. I’m operating Docker 4.26.1, however simply obtain the most recent model and you ought to be positive. When the obtain finishes begin the installer. The installer provides you with the next choices:

Simply settle for each of those choices and click on OK, except you selected to not set up WSL 2 and use Hyper-V as a substitute. Whether or not or not you need a shortcut in your desktop is completely as much as you after all 😉.

Now simply let the installer do its magic:

Carried out!

Then go forward and run the Docker Desktop software, the place you’ll have to just accept the service settlement:

After which simply select “Use really helpful settings” and click on End:

Now Docker Desktop will begin and you may be prompted to both enroll or sign up. Docker is free for private and even small-business use, so press the button to enroll and create an account. You may even use your Google or GitHub account to create one actually quick. (You can too proceed with out signing in if you wish to, and it ought to nonetheless work positive). I’m simply going to go forward and sign up with my Google account.

If all the pieces was profitable, you ought to be greeted by the next display:

Congratulations! You’ve now put in Docker Desktop and are able to go! When you nonetheless have issues, first attempt the beneath, and if that doesn’t work, google may have an answer. By no means despair!

(Solely for many who nonetheless have issues 🙈🙂)

- Hypervisor enabled at Home windows startup -
If in case you have accomplished the steps described above and are nonetheless experiencing Docker Desktop startup points, this might be as a result of the Hypervisor is put in, however not launched throughout Home windows startup. Some instruments (similar to older variations of Digital Field) and online game installers flip off hypervisor on boot. To show it again on:

    - Open an administrative console immediate.
    - Run bcdedit /set hypervisorlaunchtype auto.
    - Restart Home windows.

Making a Dockerfile

Okay, now that all of us have Docker Desktop put in and operating, let’s transfer on to the subsequent step! I’ll be utilizing VS Code for this, simply because it feels handy to me. You can too use another code editor or actually simply copy the textual content into Notepad and use a separate terminal window, it makes no distinction.

Create a base venture listing and open it in VS Code. I’ll merely name my listing AUTOGEN:

📁AUTOGEN (root venture folder)

Now contained in the AUTOGEN folder create a brand new file referred to as Dockerfile.base:

    📁AUTOGEN (root venture folder)
        📄Dockerfile.base

What’s a Dockerfile? A Dockerfile is a textual content doc that comprises all of the instructions a consumer might name on the command line to assemble a picture and finally run a Docker container. Consider this dockerfile as a recipe that Docker will observe to construct a customized picture that can be utilized to create new containers.

In a Dockerfile, you may specify the bottom picture to make use of, outline the working listing, copy recordsdata out of your native system to the container, run instructions to put in packages, expose ports for the appliance, and specify the command that must be run when a container is launched from the picture.

So open up your Dockerfile.base, and let’s sort out our Docker recipe! This might be principally based mostly on the instance suggestions from AutoGen itself, with some minor tweaks. First, let’s specify the bottom picture:

FROM python:3.11-slim-bookworm

It will use the official Python picture from Docker Hub, which relies on Debian Linux. We’ll use the slim-bookworm model, which is a light-weight model of Debian Linux. We’ll additionally use Python 3.11, which is within the vary of present really helpful variations for AutoGen on the time of writing.

Then proceed in your Dockerfile.base with the next:

RUN apt-get replace 
    && DEBIAN_FRONTEND=noninteractive apt-get set up -y --no-install-recommends 
        software-properties-common sudo
    && apt-get clear 
    && rm -rf /var/lib/apt/lists/*

I’m going to elucidate what all of the Docker instructions do as these subjects are attention-grabbing and really useful as a developer, however should you’re not keen on Dockerfiles and Linux instructions and don’t wish to do any coding stuff, you could have my blessings to skip the reasons and simply scroll right down to the completed Dockerfile on the finish of this part and replica it into your personal Dockerfile.base 😉.

  • RUN is a Dockerfile command that executes a command within the container. On this case, we’re operating the apt-get replace command, which refreshes the native bundle index with the most recent variations. && is a command separator, which lets us chain instructions.
  • DEBIAN_FRONTEND=noninteractive is an setting variable that’s set to noninteractive to stop the apt-get set up command from asking any questions in the course of the set up and simply apply default settings.
  • apt-get set up is the command to put in packages. The -y flag is used to routinely reply sure to any questions which will come up in the course of the set up course of. The --no-install-recommends flag is used to stop the set up of any really helpful packages that aren’t strictly required for the bundle to operate, maintaining it mild.
  • software-properties-common is a bundle that gives utilities for managing software program repositories. and sudo is a utility that enables us to run instructions as a superuser.
  • apt-get clear is a command that cleans up the native repository of retrieved bundle recordsdata, and rm -rf /var/lib/apt/lists/* is a command that removes the bundle lists that have been downloaded in the course of the apt-get replace command. That is performed to save lots of disk area.

Subsequent in our Dockerfile, we’ll arrange a root consumer with superuser entry:

RUN adduser --disabled-password --gecos '' autogen
RUN adduser autogen sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /and many others/sudoers
USER autogen
WORKDIR /dwelling/autogen

The primary line creates a brand new consumer named autogen with out a password and with out prompting for added data, whereas --gecos '' merely units the consumer data to an empty string. The following line provides the consumer autogen to the sudo group, granting it administrative privileges.

The third line configures the sudo group to permit members to execute instructions as root with out requiring a password. After that, we change to the autogen consumer and set the working listing to /dwelling/autogen.

Subsequent up:

ENV PATH="/dwelling/autogen/.native/bin:$PATH"
ENV OPENAI_API_KEY=paste_your_api_key_here

First, we set the PATH setting variable (utilizing Docker’s ENV command) to incorporate the .native/bin listing within the autogen consumer’s dwelling listing.

Then we set the OPENAI_API_KEY setting variable to the API key that we received from OpenAI. That is wanted in order that AutoGen Studio can entry the OpenAI API.

Be sure you paste your personal ChatGPT API key in there as a substitute of paste_your_api_key_here, ensuring to not add "" double quotes or something. You create new or further keys by going to the OpenAI API keys web page:

Okay now to proceed in our Dockerfile:

RUN pip set up pyautogen==0.2.8 autogenstudio==0.0.34a0 numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4

We simply pre-install a number of the in style packages and naturally pyautogen and autogenstudio themselves. I’ve specified two particular variations for pyautogen and autogenstudio, as these are the variations I’m utilizing when penning this tutorial. I counsel you to make use of the identical ones to be sure you have precisely the identical expertise as me. You may all the time improve the packages after you end the tutorial collection. (Don’t fear, on the finish of the final half I’ll present you ways and also you gained’t lose any of your work!)

Now subsequent up in our Dockerfile:

# Expose port
EXPOSE 8081

# Begin Command for AutoGen Studio
CMD ["autogenstudio", "ui", "--host", "0.0.0.0", "--port", "8081"]

The EXPOSE command exposes port 8081, which is the port that AutoGen Studio will run on. The CMD command specifies the command that might be run when the container is launched from the picture. On this case, we’re operating the autogenstudio command with the ui possibility, which can begin the AutoGen Studio interface. The --host and --port choices specify the host and port that the interface might be out there on. This implies we’ll solely have to begin the container and AutoGen Studio might be out there on port 8081 routinely!

Notice that we used the handle 0.0.0.0 as a substitute of the same old localhost 127.0.0.1. If we bind to the 127.. model it’s solely accessible from the identical machine – on this case, the identical Docker container. To make our software accessible from exterior the Docker container, you want to bind it to 0.0.0.0 as a substitute. It will make it accessible from any IP handle, together with out of your host machine.

To complete off our Dockerfile, we’ll add a remark on the backside for our personal future reference:

# command to construct the picture:
    # docker construct -t autogenstudio -f Dockerfile.base .
# command to run the container:
    # docker run -it --rm -p 8081:8081 --name autogenstudio autogenstudio
# Entry AutoGen Studio at http://localhost:8081 be sure you do not click on the 0.0.0.0:8081 hyperlink within the terminal, it will not work!

That is only a remark that you should use for future reference so that you don’t have to look the tutorial to search out the command to construct and run the container, we’ll use and clarify these instructions in a second, simply copy them in your future reference.

Constructing the Docker picture and operating the container

Your entire Dockerfile.base ought to now appear to be this:

FROM python:3.11-slim-bookworm

RUN apt-get replace 
    && DEBIAN_FRONTEND=noninteractive apt-get set up -y --no-install-recommends 
        software-properties-common sudo
    && apt-get clear 
    && rm -rf /var/lib/apt/lists/*

# Setup a non-root consumer 'autogen' with sudo entry
RUN adduser --disabled-password --gecos '' autogen
RUN adduser autogen sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /and many others/sudoers
USER autogen
WORKDIR /dwelling/autogen

# Set setting variable
ENV PATH="/dwelling/autogen/.native/bin:$PATH"
# Comply with the = together with your OpenAI API key (no quotes or something, simply OPENAI_API_KEY=sk-lotsOfLettersAndNumbers)
ENV OPENAI_API_KEY=

# Pre-load in style packages
RUN pip set up pyautogen==0.2.8 autogenstudio==0.0.34a0 numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4

# Expose port
EXPOSE 8081

# Begin Command for AutoGen Studio
CMD ["autogenstudio", "ui", "--host", "0.0.0.0", "--port", "8081"]

# command to construct the picture:
    # docker construct -t autogenstudio -f Dockerfile.base .
# command to run the container:
    # docker run -it --rm -p 8081:8081 --name autogenstudio autogenstudio
# Entry AutoGen Studio at http://localhost:8081 be sure you do not click on the 0.0.0.0:8081 hyperlink within the terminal, it will not work!

Okay, so with that out of the way in which, first be sure that the Docker Desktop software is operating, as we’ll want the Docker Engine course of to be up and operating. Then open up a terminal window and be sure you’re within the root venture folder, in my case AUTOGEN:

admin@DirkMasterPC /c/Coding_Vault/AUTOGEN

Then run the next command to construct the picture:

docker construct -t autogenstudio -f Dockerfile.base .

It will construct the picture and tag (-t) it with the title autogenstudio. The -f flag specifies the title of the Dockerfile to make use of, on this case Dockerfile.base. The . on the finish specifies the construct context, which is the present listing, as that is the place our Dockerfile.base is situated.

The Docker Picture might be constructed and you will note the progress operating by way of every of the steps within the Dockerfile. When it’s performed we are able to run the next command to begin the container which can routinely run AutoGen Studio:

docker run -it --rm -p 8081:8081 --name autogenstudio autogenstudio

This works by operating the docker run command, which creates a brand new container from the autogenstudio picture that we simply constructed. The -it flag specifies that we wish to run the container in interactive mode, which suggests we are able to work together with the container through the terminal.

The --rm flag specifies that we would like the container to be eliminated when it’s stopped. The -p flag specifies that we wish to map port 8081 from the container to port 8081 on our native machine. The --name flag specifies the title of the container, on this case, autogenstudio.

Now carry up your Docker Desktop software and open up the Containers tab (topmost icon within the left menu bar):

We are able to see that our container by the title autogenstudio, based mostly on the picture autogenstudio is operating on port 8081! Hooray! 🎉

Victory!

You may both click on on the blue 8081:8081 hyperlink to open up AutoGen Studio in your browser, or simply open up your browser and go to http://localhost:8081. There may be additionally a hyperlink in your terminal window that claims that Uvicorn is operating on http://0.0.0.0:8081. Don’t click on this hyperlink because the 0.0.0.0:8081 handle is barely accessible from throughout the Docker container and you might be exterior of it, so it is not going to work.

Give your self a pat on the again for a job nicely performed! You’ve arrange AutoGen Studio correctly and inside a Docker container! One fast sidenote, once we wrote the Dockerfile.base we hardcoded the ChatGPT API key into the Dockerfile to maintain issues so simple as potential. We are able to after all keep away from this however this might complicate the tutorial additional and I wish to maintain this one as low-code as potential.

Simply be sure you don’t share the Dockerfile.base or take away your API key from it first as anybody together with your API key can clearly use OpenAI’s API in your credit score. Your Docker Picture additionally has the API key hardcoded into it. There is no such thing as a motive you’d ever actually wish to share the picture although, simply don’t depart copies behind on a public laptop or one thing.

That’s it for half 1! I hope it wasn’t too troublesome. Any longer the enjoyable half begins. I’ll see you partly 2 the place we’ll dive straight into AutoGen Studio. 😎

👉 Go Again to the Full Course: Subsequent Degree Immediate Engineering with AutoGen Studio

[ad_2]

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles