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:
index.js, responsible for sending an input to the underlying LLM and retrieving an output.
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:
cd ./conversation
npm install- Open a new terminal window and run the multi app run template:
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 with a
get_weathertool available; the LLM calls the tool.
Conversation input sent: What is dapr?
Usage: prompt_tokens=30 completion_tokens=64 total_tokens=94
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: [{"id":"call_xxxx","function":{"name":"get_weather","arguments":"{\"location\":\"San Francisco, CA\",\"unit\":\"celsius\"}"}}]
- Stop and clean up application processes.
dapr stop -f .- Open a terminal and navigate to the
conversationapp. Install the dependencies if you haven't already.
cd ./conversation
npm install- Run the Dapr process alongside the application.
dapr run --app-id conversation --resources-path ../../../components/ -- npm run startThe 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 with a
get_weathertool available; the LLM calls the tool.
Conversation input sent: What is dapr?
Usage: prompt_tokens=30 completion_tokens=64 total_tokens=94
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: [{"id":"call_xxxx","function":{"name":"get_weather","arguments":"{\"location\":\"San Francisco, CA\",\"unit\":\"celsius\"}"}}]