Skip to content

Commit a5845de

Browse files
committed
updated from feedback
Signed-off-by: Filinto Duran <[email protected]>
1 parent 3d68ef4 commit a5845de

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

conversation/python/http/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This example uses the default LLM Component provided by Dapr which simply echoes
1919
1. Install dependencies:
2020

2121
<details open="true">
22-
<summary>Option 2: Using uv (faster modern alternative to pip)</summary>
22+
<summary>Option 1: Using uv (faster modern alternative to pip)</summary>
2323

2424
```
2525
cd conversation
@@ -35,7 +35,7 @@ This example uses the default LLM Component provided by Dapr which simply echoes
3535
</details>
3636
3737
<details>
38-
<summary>Option 1: Using classic pip</summary>
38+
<summary>Option 2: Using classic pip</summary>
3939
4040
<!-- STEP
4141
name: Install Python dependencies
@@ -59,7 +59,6 @@ This example uses the default LLM Component provided by Dapr which simply echoes
5959
cd ..
6060
```
6161
62-
<!-- END_STEP -->
6362
6463
2. Open a new terminal window and run the multi app run template:
6564
@@ -71,7 +70,7 @@ This example uses the default LLM Component provided by Dapr which simply echoes
7170
- '== APP - conversation == Tool calling input sent: What is the weather like in San Francisco in celsius?'
7271
- '== APP - conversation == Output message: What is the weather like in San Francisco in celsius?'
7372
- '== APP - conversation == Tool calls detected:'
74-
- '== APP - conversation == Tool call: {'id': '0', 'function': {'name': 'get_weather', 'arguments': 'location,unit'}}'
73+
- "== APP - conversation == Tool call: {'id': '0', 'function': {'name': 'get_weather', 'arguments': 'location,unit'}}"
7574
- '== APP - conversation == Function name: get_weather'
7675
- '== APP - conversation == Function arguments: location,unit'
7776
expected_stderr_lines:
@@ -101,7 +100,8 @@ This example uses the default LLM Component provided by Dapr which simply echoes
101100
102101
- The app then sends an input `What is the weather like in San Francisco in celsius?` to the `echo` Component mock LLM.
103102
- The mock LLM echoes `What is the weather like in San Francisco in celsius?` and calls the `get_weather` tool.
104-
- Since we are using the `echo` Component mock LLM, the tool call is not executed and the LLM returns `No tool calls in response`.
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.
105105
106106
```text
107107
== APP == Tool calling input sent: What is the weather like in San Francisco in celsius?
@@ -177,6 +177,9 @@ This example uses the default LLM Component provided by Dapr which simply echoes
177177
- The mock LLM echoes `What is dapr?`.
178178
- The app then sends an input `What is the weather like in San Francisco in celsius?` to the `echo` Component mock LLM.
179179
- 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.
180183
181184
```text
182185
== APP - conversation == Conversation input sent: What is dapr?

conversation/python/sdk/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This quickstart includes two example applications:
1717

1818
You can run the sample applications using either the Dapr multi-app template or the Dapr CLI directly.
1919

20-
### Option 1: Using the Multi-App Template
20+
### Use the multi-app-run template file
2121

2222
This approach uses [Dapr's multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) to simplify deployment with `dapr run -f .`.
2323

@@ -113,8 +113,8 @@ For more LLM options, see the [supported Conversation components](https://docs.d
113113
expected_stdout_lines:
114114
- "== APP - conversation-tool-calling == Input sent: calculate square root of 15"
115115
- "== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='calculate square root of 15', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='calculate', arguments='expression'))]))"
116-
- "== APP - conversation-tool-calling == Input sent: get weather in London in celsius"
117-
- "== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='get weather in London in celsius', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='get_weather', arguments='location,unit'))]))"
116+
- "== APP - conversation-tool-calling == Input sent: get weather in San Francisco in celsius"
117+
- "== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='get weather in San Francisco in celsius', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='get_weather', arguments='location,unit'))]))"
118118
expected_stderr_lines:
119119
output_match_mode: substring
120120
match_order: none
@@ -133,8 +133,8 @@ For more LLM options, see the [supported Conversation components](https://docs.d
133133
```text
134134
== APP - conversation-tool-calling == Input sent: calculate square root of 15
135135
== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='calculate square root of 15', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='calculate', arguments='expression'))]))
136-
== APP - conversation-tool-calling == Input sent: get weather in London in celsius
137-
== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='get weather in London in celsius', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='get_weather', arguments='location,unit'))]))
136+
== APP - conversation-tool-calling == Input sent: get weather in San Francisco in celsius
137+
== APP - conversation-tool-calling == Output response: ConversationResultAlpha2Choices(finish_reason='tool_calls', index=0, message=ConversationResultAlpha2Message(content='get weather in San Francisco in celsius', tool_calls=[ConversationToolCalls(id='0', function=ConversationToolCallsOfFunction(name='get_weather', arguments='location,unit'))]))
138138
```
139139

140140
<!-- END_STEP -->
@@ -152,7 +152,7 @@ For more LLM options, see the [supported Conversation components](https://docs.d
152152

153153
<!-- END_STEP -->
154154

155-
### Option 2: Using the Dapr CLI Directly
155+
### Run the apps individually
156156

157157
As an alternative to the multi-app template, you can run the application directly with the Dapr CLI.
158158

conversation/python/sdk/conversation/tool_calling.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
with DaprClient() as d:
1717
provider_component = "echo"
1818

19+
# ------------------------------------------------------------
20+
# Creating Tool Function definition using lower level API and hand-crafted JSON schema
21+
# ------------------------------------------------------------
22+
23+
# This is how to register a tool using hand-crafted JSON schema
1924
function = conversation.ConversationToolsFunction(
2025
name="calculate",
2126
description="Perform calculations",
@@ -63,7 +68,7 @@ def get_weather(location: str, unit: str) -> str:
6368
"""get weather from a location in the given unit"""
6469
return f"The weather in {location} is 25 degrees {unit}."
6570

66-
textInput = "get weather in London in celsius"
71+
textInput = "get weather in San Francisco in celsius"
6772
# use create helper function (i.e.: create_user_message, create_system_message, etc...) to create inputs easily
6873
inputs = [
6974
conversation.ConversationInputAlpha2(messages=[conversation.create_user_message(textInput)], scrub_pii=True),
@@ -84,5 +89,5 @@ def get_weather(location: str, unit: str) -> str:
8489

8590
# registered tools are also automatically set to be invoked easily when called by the LLM
8691
# using the method conversation.execute_registered_tool:
87-
# >>> print(conversation.execute_registered_tool(name="get_weather", params={"location":"London", "unit":"celsius"}))
92+
# >>> print(conversation.execute_registered_tool(name="get_weather", params={"location":"San Francisco", "unit":"celsius"}))
8893

0 commit comments

Comments
 (0)