-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conversation quickstarts updates - Python and Go (#1169)
* 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
1 parent
000e127
commit 9aef603
Showing
29 changed files
with
210 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# General | ||
.venv | ||
venv | ||
.env | ||
env | ||
*.exe | ||
*.suo | ||
*.user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
requests | ||
Flask | ||
uvicorn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dapr>=1.15.0rc2 | ||
dapr>=1.15.0rc3 | ||
typing-extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module conversation | ||
|
||
go 1.23.5 | ||
go 1.23.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dapr>=1.15.0rc3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include ../../../docker.mk | ||
include ../../../validate.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dapr>=1.14 | ||
dapr>=1.15.0rc3 | ||
typing-extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
dapr>=1.15.0rc2 | ||
dapr>=1.15.0rc3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dapr>=1.15.0rc2 | ||
dapr>=1.15.0rc3 | ||
typing-extensions |
3 changes: 2 additions & 1 deletion
3
service_invocation/python/http/order-processor/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.