Skip to content

Commit

Permalink
Merge branch 'release-1.15' into python-sdk-1.15.0rc2
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <[email protected]>
  • Loading branch information
elena-kolevska authored Jan 28, 2025
2 parents 87cbc68 + 7dfc415 commit f7ebc65
Show file tree
Hide file tree
Showing 65 changed files with 1,603 additions and 292 deletions.
6 changes: 3 additions & 3 deletions .github/env/global.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DAPR_CLI_VERSION: 1.14.1
DAPR_RUNTIME_VERSION: 1.15.0-rc.2
DAPR_CLI_VERSION: 1.15.0-rc.2
DAPR_RUNTIME_VERSION: 1.15.0-rc.5
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v${DAPR_CLI_VERSION}/install/
DAPR_DEFAULT_IMAGE_REGISTRY: ghcr

Expand All @@ -11,4 +11,4 @@ GOVER: 1.22

KUBERNETES_VERSION: v1.32.0
KIND_VERSION: v0.26.0
KIND_IMAGE_SHA: sha256:c48c62eac5da28cdadcf560d1d8616cfa6783b58f0d94cf63ad1bf49600cb027
KIND_IMAGE_SHA: sha256:c48c62eac5da28cdadcf560d1d8616cfa6783b58f0d94cf63ad1bf49600cb027
21 changes: 15 additions & 6 deletions actors/csharp/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Let's take a look at the Dapr [Actors building block](https://docs.dapr.io/devel
For this example, you will need:

- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started).
- [.NET 7 SDK](https://dotnet.microsoft.com/download).
- [.NET 8 SDK](https://dotnet.microsoft.com/download).
- Docker Desktop

### Step 2: Set up the environment
Expand All @@ -34,7 +34,7 @@ Run the `SmartDevice.Service`, which will start service itself and the Dapr side
<!-- STEP
name: Run actor service
expected_stdout_lines:
- "Request finished HTTP/1.1 GET http://127.0.0.1:5001/healthz - 200"
- "Request finished HTTP/1.1 GET http://127.0.0.1:5001/dapr/config - 200"
expected_stderr_lines:
working_dir: .
output_match_mode: substring
Expand All @@ -50,14 +50,23 @@ dapr run --app-id actorservice --app-port 5001 --app-protocol http --dapr-http-p
Expected output:

```bash
== APP == info: Microsoft.Hosting.Lifetime[14]
== APP == Now listening on: http://localhost:5001
== APP == info: Microsoft.Hosting.Lifetime[0]
== APP == Application started. Press Ctrl+C to shut down.
== APP == info: Microsoft.Hosting.Lifetime[0]
== APP == Hosting environment: Production
== APP == info: Microsoft.Hosting.Lifetime[0]
== APP == info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
== APP == Request starting HTTP/1.1 GET http://127.0.0.1:5001/healthz - -
== APP == Request starting HTTP/1.1 GET http://127.0.0.1:5001/dapr/config - application/json -
== APP == warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
== APP == Failed to determine the https port for redirect.
== APP == info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
== APP == Executing endpoint 'Dapr Actors Health Check'
== APP == Executing endpoint 'Dapr Actors Config'
== APP == info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
== APP == Executed endpoint 'Dapr Actors Health Check'
== APP == Executed endpoint 'Dapr Actors Config'
== APP == info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
== APP == Request finished HTTP/1.1 GET http://127.0.0.1:5001/healthz - - - 200 - text/plain 5.2599ms
== APP == Request finished HTTP/1.1 GET http://127.0.0.1:5001/dapr/config - 200 - application/json 30.6175ms
```

### Step 4: Run the client app
Expand Down
2 changes: 1 addition & 1 deletion actors/csharp/sdk/client/SmartDevice.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.Actors" Version="1.14.*-*" />
<PackageReference Include="Dapr.Actors" Version="1.15.0-rc02" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions actors/csharp/sdk/service/SmartDevice.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.Actors" Version="1.14.*-*" />
<PackageReference Include="Dapr.Actors.AspNetCore" Version="1.14.*-*" />
<PackageReference Include="Dapr.Actors" Version="1.15.0-rc02" />
<PackageReference Include="Dapr.Actors.AspNetCore" Version="1.15.0-rc02" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion bindings/csharp/sdk/batch/batch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="1.14.*-*" />
<PackageReference Include="Dapr.AspNetCore" Version="1.15.0-rc02" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions bindings/csharp/sdk/batch/program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ limitations under the License.
options.SupportedCultures = [invariantCulture];
});

builder.Services.AddDaprClient();

var app = builder.Build();

if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); }

app.UseRequestLocalization();

// Triggered by Dapr input binding
app.MapPost("/" + cronBindingName, async () =>
app.MapPost("/" + cronBindingName, async (DaprClient client) =>
{
Console.WriteLine("Processing batch..");

string jsonFile = File.ReadAllText("../../../orders.json");
var ordersArray = JsonSerializer.Deserialize<Orders>(jsonFile);
using var client = new DaprClientBuilder().Build();
foreach (Order ord in ordersArray?.orders ?? new Order[] { })
{
var sqlText = $"insert into orders (orderid, customer, price) values ({ord.OrderId}, '{ord.Customer}', {ord.Price});";
Expand All @@ -65,5 +66,5 @@ limitations under the License.

await app.RunAsync();

public record Order([property: JsonPropertyName("orderid")] int OrderId, [property: JsonPropertyName("customer")] string Customer, [property: JsonPropertyName("price")] float Price);
public record Orders([property: JsonPropertyName("orders")] Order[] orders);
public sealed record Order([property: JsonPropertyName("orderid")] int OrderId, [property: JsonPropertyName("customer")] string Customer, [property: JsonPropertyName("price")] float Price);
public sealed record Orders([property: JsonPropertyName("orders")] Order[] orders);
3 changes: 2 additions & 1 deletion bindings/python/sdk/batch/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dapr>=1.15.0rc2
Flask
typing-extensions
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,2 +1,3 @@
requests
flask
flask
urllib3>=2.2.2 # not directly required, pinned by Snyk to avoid a vulnerability
7 changes: 7 additions & 0 deletions conversation/components/conversation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: echo
spec:
type: conversation.echo
version: v1
85 changes: 85 additions & 0 deletions conversation/csharp/http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Dapr Conversation API (C# 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.

> **Note:** This example leverages HTTP `requests` only. If you are looking for the example using the Dapr Client SDK (recommended) [click here](../sdk/).
This quickstart includes one app:

- Conversation, 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 file](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) and Dapr CLI with `dapr run -f .`.

This example uses the default LLM Component provided by Dapr which simply echoes the input provided, for testing purposes. Integrate with popular LLM models by using one of the other [supported conversation components](https://v1-15.docs.dapr.io/reference/components-reference/supported-conversation/).

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: 15
-->

```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
-->

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

<!-- END_STEP -->

## Run the app individually

1. Open a terminal and run the `conversation` app. Build the dependencies if you haven't already.

```bash
cd ./conversation
dotnet build
```

2. Run the Dapr process alongside the application.

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

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?
```
67 changes: 67 additions & 0 deletions conversation/csharp/http/conversation/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2024 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.
*/

using System.Net.Http;
using System.Text.Json;
using System.Text;

class Program
{
private const string ConversationComponentName = "echo";

static async Task Main(string[] args)
{
var daprHost = Environment.GetEnvironmentVariable("DAPR_HOST") ?? "http://localhost";
var daprHttpPort = Environment.GetEnvironmentVariable("DAPR_HTTP_PORT") ?? "3500";

var client = new HttpClient
{
Timeout = TimeSpan.FromSeconds(15)
};

var inputBody = new
{
name = "echo",
inputs = new[] { new { message = "What is dapr?" } },
parameters = new { },
metadata = new { }
};

var daprUrl = $"{daprHost}:{daprHttpPort}/v1.0-alpha1/conversation/{ConversationComponentName}/converse";

try
{
var content = new StringContent(JsonSerializer.Serialize(inputBody), Encoding.UTF8, "application/json");

// Send a request to the echo mock LLM component
var response = await client.PostAsync(daprUrl, content);
response.EnsureSuccessStatusCode();

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

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

// Parse the response
var data = JsonSerializer.Deserialize<Dictionary<string, List<Dictionary<string, string>>>>(responseBody);
var result = data?["outputs"]?[0]?["result"];

Console.WriteLine("Output response: " + result);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
14 changes: 14 additions & 0 deletions conversation/csharp/http/conversation/Program.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="9.0.1" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions conversation/csharp/http/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 1
common:
resourcesPath: ../../components/
apps:
- appDirPath: ./conversation/
appID: conversation
daprHTTPPort: 3500
command: ["dotnet", "run"]
2 changes: 2 additions & 0 deletions conversation/csharp/http/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include ../../../docker.mk
include ../../../validate.mk
Loading

0 comments on commit f7ebc65

Please sign in to comment.