Install Dapr and make a first model call
Install Dapr and make a first model call. In this video you'll set up Dapr without containers, and reach a model through configuration only. Dapr, the Distributed Application Runtime, runs as a small process next to your application, called a sidecar. Your code talks to the sidecar, and the sidecar talks to data stores, message brokers, and model providers, through components: small configuration files. Dapr Agents is an open source Python framework that builds durable agents on top of it. In this lesson you will install the Dapr command line tool and the slim runtime at pinned versions, start the three services that durable workflows need, and call a model through a conversation component. Before you start, you need curl, jq, Python 3, and a model endpoint that speaks the OpenAI API, with its key. The first command checks the tools. curl, jq and Python are there. The command line tool, dapr, installs and starts the runtime. I install version 1.19.1 and pin it, so that these steps do not change under you. The runtime comes next. Normally dapr init starts Docker containers. I use slim mode, which only downloads the program files, so no containers are needed. The download is a few hundred megabytes, so this part of the video is sped up. Slim mode keeps everything in the dot dapr folder of my home directory. Removing that folder removes Dapr. Three programs came down. The program daprd is the sidecar. Placement decides which process owns a durable workflow, and the scheduler wakes a workflow after a delay or a restart. Slim mode does not start them, so a short script does, together with Redis, which stores the workflow state. The script starts each service in the background and saves the number of its process, the ID, so that I can stop it later. Everything listens on the local address only. I move the health and metrics ports away from 8080 and 9090, which other tools often use. Now Python. I create a virtual environment and install dapr-agents, version 1.1.0. It brings the Dapr Python library with it. The installation takes a minute or two, so it is sped up as well. Pinning matters for agents too. A new release can change how an agent behaves, so I record exactly what I tested. The model is a Dapr component, a small configuration file, in YAML format, in a resources folder. This one has the OpenAI-compatible type, so it works with any provider that speaks that protocol. The key, the address, and the model name come from environment variables that I loaded before recording. To change provider, you change those values, not the code. The program has four lines. DaprChatClient sends a prompt to the sidecar, and the sidecar calls the model through the component named llm-provider. The dapr run command starts the sidecar and my program together, and stops both when the program ends. The app ID names the process, and the resources path points to the component folder. I limit the sidecar log to errors. The model takes a few seconds. The wording of the answer differs on every run. That is the base. Dapr 1.19.1 runs on this machine without containers, three services are up, and a Python program reaches a model through configuration only. Diagrid publishes a dashboard for Dapr that runs on your own machine. I started it before recording, with one command, on port 9095. My program ended after one call, so I keep a sidecar running alone, on the same resources folder: dapr run without a program does that. The Components page lists what the sidecar loaded from the resources folder: one component, llm-provider, of the conversation type, OpenAI compatible, loaded by the llm-call app. The key, the address, and the model name are references to environment variables of the sidecar. The dashboard shows the names, never the values. The model is configuration, not code. In this lesson you learned that slim mode needs no containers, so placement and the scheduler run as plain processes, that the model is a component, so you change provider in a YAML file and not in the code, and that dapr run starts the sidecar and your program together, and stops both at the end.