Skip to content

Commit

Permalink
Conversation quickstarts updates - Python and Go (#1169)
Browse files Browse the repository at this point in the history
* Adds python conversation api sdk quickstart. Updates python sdk version. Updates parameter name in conversation quickstart in Go.

Signed-off-by: Elena Kolevska <[email protected]>

* Fixes .net http quickstart for Conversation API

Signed-off-by: Elena Kolevska <[email protected]>

* rename

Signed-off-by: Elena Kolevska <[email protected]>

* Fixes js conversation quickstart

Signed-off-by: Elena Kolevska <[email protected]>

* Older dependency

Signed-off-by: Elena Kolevska <[email protected]>

* Sets up a clean virtual environment for every quickstart

Signed-off-by: Elena Kolevska <[email protected]>

* Apply suggestions from code review

Co-authored-by: Mark Fussell <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>

* Adds uvicorn in requirements.txt

Signed-off-by: Elena Kolevska <[email protected]>

* Runs the install step

Signed-off-by: Elena Kolevska <[email protected]>

---------

Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>
Co-authored-by: Mark Fussell <[email protected]>
  • Loading branch information
elena-kolevska and msfussell authored Feb 27, 2025
1 parent 000e127 commit 9aef603
Show file tree
Hide file tree
Showing 29 changed files with 210 additions and 32 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/validate_python_quickstarts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ jobs:
else
pushd $building_block/python/$variant
echo "Validating $building_block/python/$variant quickstart"
python3 -m venv .venv
source .venv/bin/activate
make validate
deactivate
rm -rf .venv
popd
fi
done
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# General
.venv
venv
.env
env
*.exe
*.suo
*.user
Expand Down
1 change: 1 addition & 0 deletions bindings/python/http/batch/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
requests
Flask
uvicorn
3 changes: 2 additions & 1 deletion bindings/python/sdk/batch/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dapr>=1.15.0rc2
dapr>=1.15.0rc3
Flask
uvicorn
typing-extensions
werkzeug>=3.0.3 # not directly required, pinned by Snyk to avoid a vulnerability
3 changes: 2 additions & 1 deletion configuration/python/http/order-processor/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests
flask
Flask
uvicorn
urllib3>=2.2.2 # not directly required, pinned by Snyk to avoid a vulnerability
2 changes: 1 addition & 1 deletion configuration/python/sdk/order-processor/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dapr>=1.15.0rc2
dapr>=1.15.0rc3
typing-extensions
4 changes: 2 additions & 2 deletions conversation/csharp/http/conversation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static async Task Main(string[] args)
var inputBody = new
{
name = "echo",
inputs = new[] { new { message = "What is dapr?" } },
inputs = new[] { new { content = "What is dapr?" } },
parameters = new { },
metadata = new { }
};
Expand All @@ -49,7 +49,7 @@ static async Task Main(string[] args)
var response = await client.PostAsync(daprUrl, content);
response.EnsureSuccessStatusCode();

Console.WriteLine("Input sent: " + inputBody.inputs[0].message);
Console.WriteLine("Input sent: " + inputBody.inputs[0].content);

var responseBody = await response.Content.ReadAsStringAsync();

Expand Down
2 changes: 1 addition & 1 deletion conversation/go/http/conversation/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {

var inputBody = `{
"name": "echo",
"inputs": [{"message":"What is dapr?"}],
"inputs": [{"content":"What is dapr?"}],
"parameters": {},
"metadata": {}
}`
Expand Down
2 changes: 1 addition & 1 deletion conversation/go/http/conversation/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module conversation

go 1.23.5
go 1.23.6
4 changes: 2 additions & 2 deletions conversation/go/sdk/conversation/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func main() {
}

input := dapr.ConversationInput{
Message: "What is dapr?",
Content: "What is dapr?",
// Role: nil, // Optional
// ScrubPII: nil, // Optional
}

fmt.Println("Input sent:", input.Message)
fmt.Println("Input sent:", input.Content)

var conversationComponent = "echo"

Expand Down
20 changes: 10 additions & 10 deletions conversation/go/sdk/conversation/go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module conversation

go 1.23.5
go 1.23.6

require github.com/dapr/go-sdk v1.12.0-rc.1
require github.com/dapr/go-sdk v1.12.0-rc.2

require (
github.com/dapr/dapr v1.15.0-rc.1 // indirect
github.com/dapr/dapr v1.15.0-rc.18 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
google.golang.org/grpc v1.68.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250224174004-546df14abb99 // indirect
google.golang.org/grpc v1.70.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
18 changes: 18 additions & 0 deletions conversation/go/sdk/conversation/go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/dapr/dapr v1.15.0-rc.1 h1:7JP3zSannxQwV27A9pPR2b/DSNmgcSjJOhRDwM4eFpQ=
github.com/dapr/dapr v1.15.0-rc.1/go.mod h1:SycZrBWgfmog+C5T4p0X6VIpnREQ3xajrYxdih+gn9w=
github.com/dapr/dapr v1.15.0-rc.18 h1:Y4lxefmhhlm2AM+zCEdvcDBe4BpqISBIzPRcS0ak1pY=
github.com/dapr/dapr v1.15.0-rc.18/go.mod h1:556Dd0N1wl6hWzVj9POYWa2D7dSlJ06MAbXNbvbxDIo=
github.com/dapr/go-sdk v1.12.0-rc.1 h1:KK92BahLmwGowVRjFxsjySl25M6wwuJSjesYIIF6h0c=
github.com/dapr/go-sdk v1.12.0-rc.1/go.mod h1:OxCF7Eh8IZvmNv6Euk+mnLrehJyLQRYb4TAU7uHq7Ow=
github.com/dapr/go-sdk v1.12.0-rc.2 h1:fHpS9FwjEbPTZvR8PtnJM9N6hRCkqGpDbk3Xjjl28oc=
github.com/dapr/go-sdk v1.12.0-rc.2/go.mod h1:RpZJ/pNfODlyk6x+whdtCrFI1/o0X67LCSwZeAZa64U=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
Expand All @@ -24,20 +28,34 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250224174004-546df14abb99 h1:ZSlhAUqC4r8TPzqLXQ0m3upBNZeF+Y8jQ3c4CR3Ujms=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250224174004-546df14abb99/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I=
google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
2 changes: 1 addition & 1 deletion conversation/javascript/http/conversation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function main() {

const inputBody = {
name: "echo",
inputs: [{ message: "What is dapr?" }],
inputs: [{ content: "What is dapr?" }],
parameters: {},
metadata: {},
};
Expand Down
2 changes: 1 addition & 1 deletion conversation/python/http/conversation/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

input = {
'name': 'echo',
'inputs': [{'message':'What is dapr?'}],
'inputs': [{'content':'What is dapr?'}],
'parameters': {},
'metadata': {}
}
Expand Down
97 changes: 97 additions & 0 deletions conversation/python/sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Dapr Conversation API (Python HTTP)

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](https://v1-15.docs.dapr.io/developing-applications/building-blocks/conversation/conversation-overview/) link for more information about Dapr and the Conversation API.

This quickstart includes one app:

- `app.py`, responsible for sending an input to the underlying LLM and retrieving an output.

## Run the app with the template file

This section shows how to run the application using the [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`.

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://v1-15.docs.dapr.io/reference/components-reference/supported-conversation/).

1. Install dependencies:

<!-- STEP
name: Install Python dependencies
-->

```bash
cd ./conversation
pip3 install -r requirements.txt
cd ..
```

<!-- END_STEP -->

2. Open a new terminal window and run the multi app run template:

<!-- STEP
name: Run multi app run template
expected_stdout_lines:
- '== APP - conversation == Input sent: What is dapr?'
- '== APP - conversation == Output response: What is dapr?'
expected_stderr_lines:
output_match_mode: substring
match_order: none
background: true
sleep: 15
timeout_seconds: 30
-->

```bash
dapr run -f .
```

The terminal console output should look similar to this, where:

- The app sends an input `What is dapr?` to the `echo` Component mock LLM.
- The mock LLM echoes `What is dapr?`.

```text
== APP - conversation == Input sent: What is dapr?
== APP - conversation == Output response: What is dapr?
```

<!-- END_STEP -->

2. Stop and clean up application processes.

<!-- STEP
name: Stop multi-app run
sleep: 5
-->

```bash
dapr stop -f .
```

<!-- END_STEP -->

## Run the app with the Dapr CLI

1. Install dependencies:

Open a terminal and run:

```bash
cd ./conversation
pip3 install -r requirements.txt
```

2. Run the application:

```bash
dapr run --app-id conversation --resources-path ../../../components -- python3 app.py
```

You should see the output:

```bash
== APP == Input sent: What is dapr?
== APP == Output response: What is dapr?
```
34 changes: 34 additions & 0 deletions conversation/python/sdk/conversation/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ------------------------------------------------------------
# Copyright 2025 The Dapr Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------
from dapr.clients import DaprClient
from dapr.clients.grpc._request import ConversationInput

with DaprClient() as d:
inputs = [
ConversationInput(content="What is dapr?", role='user', scrub_pii=True),
]

metadata = {
'model': 'modelname',
'key': 'authKey',
'cacheTTL': '10m',
}

print('Input sent: What is dapr?')

response = d.converse_alpha1(
name='echo', inputs=inputs, temperature=0.7, context_id='chat-123', metadata=metadata
)

for output in response.outputs:
print(f'Output response: {output.result}')
1 change: 1 addition & 0 deletions conversation/python/sdk/conversation/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dapr>=1.15.0rc3
7 changes: 7 additions & 0 deletions conversation/python/sdk/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 1
common:
resourcesPath: ../../components/
apps:
- appID: conversation
appDirPath: ./conversation/
command: ["python3", "app.py"]
2 changes: 2 additions & 0 deletions conversation/python/sdk/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../docker.mk
include ../../../validate.mk
2 changes: 1 addition & 1 deletion cryptography/python/sdk/crypto-quickstart/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dapr>=1.14
dapr>=1.15.0rc3
typing-extensions
6 changes: 5 additions & 1 deletion jobs/python/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ This quickstart includes two apps:

## Install dependencies

<!-- STEP
name: Install python dependencies
-->
```bash
pip install -r requirements.txt
pip3 install -r requirements.txt
```
<!-- END_STEP -->

## Run all apps with multi-app run template file

Expand Down
3 changes: 2 additions & 1 deletion pub_sub/python/http/order-processor/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Flask
dapr
uvicorn
dapr>=1.15.0rc3
cloudevents
werkzeug>=3.0.3 # not directly required, pinned by Snyk to avoid a vulnerability
2 changes: 1 addition & 1 deletion pub_sub/python/sdk/checkout/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dapr>=1.15.0rc2
dapr>=1.15.0rc3
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fastapi
dapr-ext-fastapi-dev
dapr-ext-fastapi>=1.15.0rc3
cloudevents
uvicorn
anyio>=4.4.0 # not directly required, pinned by Snyk to avoid a vulnerability
2 changes: 1 addition & 1 deletion pub_sub/python/sdk/order-processor/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Flask
dapr>=1.15.0rc2
dapr>=1.15.0rc3
cloudevents
uvicorn
typing-extensions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dapr>=1.15.0rc2
dapr>=1.15.0rc3
typing-extensions
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Flask
dapr>=1.15.0rc2
uvicorn
dapr>=1.15.0rc3
typing-extensions
werkzeug>=3.0.3 # not directly required, pinned by Snyk to avoid a vulnerability

Loading

0 comments on commit 9aef603

Please sign in to comment.