In this quickstart, you'll send an input to a mock Large Language Model (LLM) using Dapr's Conversation API. This API is responsible for providing one consistent API entry point to talk to underlying LLM providers.
Visit this link for more information about Dapr and the Conversation API.
Note: This example leverages HTTP
requestsonly.
This quickstart includes one app:
app.py, responsible for sending an input to the underlying LLM and retrieving an output. It includes a secondary conversation request to showcase tool calling to the underlying LLM.
This section shows how to run the application using the multi-app run template files with dapr run -f ..
This example uses the Ollama LLM component for local inference. You can switch to the OpenAI component by adding your API token in the provided OpenAI component file and changing the component name from ollama to openai. For other available integrations, see the other supported conversation components.
- Install dependencies:
uv sync- Open a new terminal window and run the multi app run template:
uv run dapr run -f .The terminal console output should look similar to this, where:
- The app first sends an input
What is dapr?to the Ollama LLM component with a structured JSON response format. - The LLM returns a JSON object with an
answerfield describing Dapr. - The app then sends a weather request to the component with tools available to the LLM.
- The LLM responds with a tool call to
get_weather.
Conversation input sent: What is dapr?
Output response: { "answer": "Dapr is an open-source, cross-platform microservices framework..." }
Tool calling input sent: What is the weather like in San Francisco in celsius?
Tool calls detected:
Tool call: {'id': 'call_xxxx', 'function': {'name': 'get_weather', 'arguments': '...'}}
Function name: get_weather
Function arguments: ...
- Stop and clean up application processes.
dapr stop -f .- Install dependencies:
uv sync- Run the application:
cd ./conversation
dapr run --app-id conversation --resources-path ../../../components -- uv run python app.py- The app first sends an input
What is dapr?to the Ollama LLM component with a structured JSON response format. - The LLM returns a JSON object with an
answerfield describing Dapr. - The app then sends a weather request with tools available to the LLM.
- The LLM responds with a tool call to
get_weather.
Conversation input sent: What is dapr?
Output response: { "answer": "Dapr is an open-source, cross-platform microservices framework..." }
Tool calling input sent: What is the weather like in San Francisco in celsius?
Tool calls detected:
Tool call: {'id': 'call_xxxx', 'function': {'name': 'get_weather', 'arguments': '...'}}
Function name: get_weather
Function arguments: ...