Skip to content

Commit 207a558

Browse files
Merge pull request #1215 from filintod/filinto/conversation-sdk-116
update for Dapr 1.16 conversation SDK Python quickstart
2 parents 0c29b5d + e492101 commit 207a558

File tree

7 files changed

+460
-208
lines changed

7 files changed

+460
-208
lines changed

conversation/python/http/README.md

Lines changed: 163 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -16,113 +16,178 @@ This section shows how to run the application using the [multi-app run template
1616

1717
This example uses the default LLM Component provided by Dapr which simply echoes the input provided, for testing purposes. Here are other [supported Conversation components](https://docs.dapr.io/reference/components-reference/supported-conversation/).
1818

19-
1. Install dependencies:
20-
21-
<!-- STEP
22-
name: Install Python dependencies
23-
-->
19+
1. Install dependencies:
20+
21+
<details open="true">
22+
<summary>Option 1: Using uv (faster modern alternative to pip)</summary>
23+
24+
```
25+
cd conversation
26+
27+
python3 -m venv .venv
28+
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
29+
30+
# If you don't have uv installed yet, install it first:
31+
# pip install uv
32+
uv pip install -r requirements.txt
33+
```
34+
35+
</details>
36+
37+
<details>
38+
<summary>Option 2: Using classic pip</summary>
39+
40+
<!-- STEP
41+
name: Install Python dependencies
42+
-->
43+
44+
```bash
45+
cd conversation
46+
47+
python3 -m venv .venv
48+
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
49+
50+
pip install -r requirements.txt
51+
```
52+
53+
<!-- END_STEP -->
54+
55+
</details>
56+
57+
```bash
58+
# Return to the parent directory
59+
cd ..
60+
```
2461
25-
```bash
26-
cd ./conversation
27-
pip3 install -r requirements.txt
28-
cd ..
29-
```
30-
31-
<!-- END_STEP -->
3262
3363
2. Open a new terminal window and run the multi app run template:
3464
35-
<!-- STEP
36-
name: Run multi app run template
37-
expected_stdout_lines:
38-
- '== APP - conversation == Conversation input sent: What is dapr?'
39-
- '== APP - conversation == Output response: What is dapr?'
40-
- '== APP - conversation == Tool calling input sent: What is the weather like in San Francisco in celsius?'
41-
- '== APP - conversation == Output message: What is the weather like in San Francisco in celsius?'
42-
- '== APP - conversation == Tool calls detected:'
43-
- "== APP - conversation == Tool call: {'id': '0', 'function': {'name': 'get_weather', 'arguments':"
44-
- '== APP - conversation == Function name: get_weather'
45-
- '== APP - conversation == Function arguments: '
46-
expected_stderr_lines:
47-
output_match_mode: substring
48-
match_order: none
49-
background: true
50-
sleep: 15
51-
timeout_seconds: 30
52-
-->
53-
54-
```bash
55-
dapr run -f .
56-
```
57-
58-
The terminal console output should look similar to this, where:
59-
60-
- The app first sends an input `What is dapr?` to the `echo` Component mock LLM.
61-
- The mock LLM echoes `What is dapr?`.
62-
- The app then sends a weather request to the component with tools available to the LLM.
63-
- The LLM will either respond back with a tool call for the user, or an ask for more information.
64-
65-
```text
66-
== APP - conversation == Input sent: What is dapr?
67-
== APP - conversation == Output response: What is dapr?
68-
```
69-
70-
- The app then sends an input `What is the weather like in San Francisco in celsius?` to the `echo` Component mock LLM.
71-
- The mock LLM echoes `What is the weather like in San Francisco in celsius?` and calls the `get_weather` tool.
72-
- Since we are using the `echo` Component mock LLM, the tool call is not executed and the LLM returns `No tool calls in response`.
73-
74-
```text
75-
== APP == Tool calling input sent: What is the weather like in San Francisco in celsius?
76-
== APP == Output message: What is the weather like in San Francisco in celsius?
77-
== APP == Tool calls detected:
78-
== APP == Tool call: {'id': '0', 'function': {'name': 'get_weather', 'arguments': 'location,unit'}}
79-
== APP == Function name: get_weather
80-
== APP == Function arguments: location,unit
81-
```
82-
83-
<!-- END_STEP -->
84-
85-
2. Stop and clean up application processes.
86-
87-
<!-- STEP
88-
name: Stop multi-app run
89-
sleep: 5
90-
-->
91-
92-
```bash
93-
dapr stop -f .
94-
```
95-
96-
<!-- END_STEP -->
65+
<!-- STEP
66+
name: Run multi app run template
67+
expected_stdout_lines:
68+
- '== APP - conversation == Conversation input sent: What is dapr?'
69+
- '== APP - conversation == Output response: What is dapr?'
70+
- '== APP - conversation == Tool calling input sent: What is the weather like in San Francisco in celsius?'
71+
- '== APP - conversation == Output message: What is the weather like in San Francisco in celsius?'
72+
- '== APP - conversation == Tool calls detected:'
73+
- "== APP - conversation == Tool call: {'id': '0', 'function': {'name': 'get_weather', 'arguments': 'location,unit'}}"
74+
- '== APP - conversation == Function name: get_weather'
75+
- '== APP - conversation == Function arguments: location,unit'
76+
expected_stderr_lines:
77+
output_match_mode: substring
78+
match_order: none
79+
background: true
80+
sleep: 15
81+
timeout_seconds: 30
82+
-->
83+
84+
```bash
85+
source conversation/.venv/bin/activate
86+
dapr run -f .
87+
```
88+
89+
The terminal console output should look similar to this, where:
90+
91+
- The app first sends an input `What is dapr?` to the `echo` Component mock LLM.
92+
- The mock LLM echoes `What is dapr?`.
93+
- The app then sends a weather request to the component with tools available to the LLM.
94+
- The LLM will either respond back with a tool call for the user, or an ask for more information.
95+
96+
```text
97+
== APP - conversation == Input sent: What is dapr?
98+
== APP - conversation == Output response: What is dapr?
99+
```
100+
101+
- The app then sends an input `What is the weather like in San Francisco in celsius?` to the `echo` Component mock LLM.
102+
- The mock LLM echoes `What is the weather like in San Francisco in celsius?` and calls the `get_weather` tool.
103+
- Since we are using the `echo` Component mock LLM, the tool call is not executed and the LLM returns but we return a simulated `tool call` response.
104+
The response is mocked to showcase the tool call response and what was sent as the tool definition, like the function name and arguments.
105+
106+
```text
107+
== APP == Tool calling input sent: What is the weather like in San Francisco in celsius?
108+
== APP == Output message: What is the weather like in San Francisco in celsius?
109+
== APP - conversation == Tool calls detected:
110+
== APP - conversation == Tool call: {'id': '0', 'function': {'name': 'get_weather', 'arguments': 'location,unit'}}
111+
== APP - conversation == Function name: get_weather
112+
== APP - conversation == Function arguments: location,unit
113+
```
114+
115+
<!-- END_STEP -->
116+
117+
3. Stop and clean up application processes.
118+
119+
<!-- STEP
120+
name: Stop multi-app run
121+
sleep: 5
122+
-->
123+
124+
```bash
125+
dapr stop -f .
126+
```
127+
128+
<!-- END_STEP -->
97129
98130
## Run the app with the Dapr CLI
99131
100132
1. Install dependencies:
101133
102-
Open a terminal and run:
103-
104-
```bash
105-
cd ./conversation
106-
pip3 install -r requirements.txt
107-
```
134+
Open a terminal and run:
135+
136+
```bash
137+
cd ./conversation
138+
```
139+
140+
<details open="true">
141+
<summary>Option 1: Using uv (faster alternative to pip)</summary>
142+
143+
```bash
144+
python3 -m venv .venv
145+
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
146+
# If you don't have uv installed yet, install it first:
147+
# pip install uv
148+
uv pip install -r requirements.txt
149+
```
150+
151+
</details>
152+
153+
<details>
154+
<summary>Option 2: Using classic pip</summary>
155+
156+
```bash
157+
python3 -m venv .venv
158+
source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
159+
pip3 install -r requirements.txt
160+
```
161+
162+
</details>
108163
109164
2. Run the application:
110165
111-
```bash
112-
dapr run --app-id conversation --resources-path ../../../components -- python3 app.py
113-
```
114-
115-
The terminal console output should look similar to this, where:
116-
117-
- The app first sends an input `What is dapr?` to the `echo` Component mock LLM.
118-
- The mock LLM echoes `What is dapr?`.
119-
- The app then sends an input `What is the weather like in San Francisco in celsius?` to the `echo` Component mock LLM.
120-
- The mock LLM echoes `What is the weather like in San Francisco in celsius?`
121-
122-
```text
123-
== APP - conversation == Conversation input sent: What is dapr?
124-
== APP - conversation == Output response: What is dapr?
125-
== APP - conversation == Tool calling input sent: What is the weather like in San Francisco in celsius?
126-
== APP - conversation == Output message: What is the weather like in San Francisco in celsius?
127-
== APP - conversation == No tool calls in response
128-
```
166+
```bash
167+
# Make sure your virtual environment is activated
168+
# If not already activated, run:
169+
# source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
170+
171+
dapr run --app-id conversation --resources-path ../../../components -- python3 app.py
172+
```
173+
174+
The terminal console output should look similar to this, where:
175+
176+
- The app first sends an input `What is dapr?` to the `echo` Component mock LLM.
177+
- The mock LLM echoes `What is dapr?`.
178+
- The app then sends an input `What is the weather like in San Francisco in celsius?` to the `echo` Component mock LLM.
179+
- The mock LLM echoes `What is the weather like in San Francisco in celsius?`
180+
- The mock also "calls" the `get_weather` tool.
181+
- Since we are using the `echo` Component mock LLM, the tool call is not executed and the LLM returns but we return a simulated `tool call` response.
182+
The response is mocked to showcase the tool call response and what was sent as the tool definition, like the function name and arguments.
183+
184+
```text
185+
== APP - conversation == Conversation input sent: What is dapr?
186+
== APP - conversation == Output response: What is dapr?
187+
== APP - conversation == Tool calling input sent: What is the weather like in San Francisco in celsius?
188+
== APP - conversation == Output message: What is the weather like in San Francisco in celsius?
189+
== APP - conversation == Tool calls detected:
190+
== APP - conversation == Tool call: {'id': '0', 'function': {'name': 'get_weather', 'arguments': 'location,unit'}}
191+
== APP - conversation == Function name: get_weather
192+
== APP - conversation == Function arguments: location,unit
193+
```

0 commit comments

Comments
 (0)