Skip to content

Commit 7b5ca4f

Browse files
authored
Add .NET client for LLM Conversations support (#1382)
* Updated prototype Signed-off-by: Whit Waldo <[email protected]> * Added Dapr.AI project and unit test project to contain the conversational building block (and potentially future other projects) Signed-off-by: Whit Waldo <[email protected]> * Changed default values Signed-off-by: Whit Waldo <[email protected]> * Removed unnecessary method Signed-off-by: Whit Waldo <[email protected]> * Added a few unit tests Signed-off-by: Whit Waldo <[email protected]> * Added example project Signed-off-by: Whit Waldo <[email protected]> * Added missing copyright headers Signed-off-by: Whit Waldo <[email protected]> * Changed type name -> DaprLlmInput to DaprConversationInput Signed-off-by: Whit Waldo <[email protected]> * Returning read only list Signed-off-by: Whit Waldo <[email protected]> * Update to use IReadOnlyDictionary Signed-off-by: Whit Waldo <[email protected]> * Added method to abstract class Signed-off-by: Whit Waldo <[email protected]> * Striving for consistency in how properties are specified on the record Signed-off-by: Whit Waldo <[email protected]> * Refactored enum extensions out to Dapr.Common since it will be used in AI project Signed-off-by: Whit Waldo <[email protected]> * Added JSON converter for System.Text.Json to handle enum serialization based on the enum member attributes Signed-off-by: Whit Waldo <[email protected]> * Added unit tests to prove out generic enum JSON converter using EnumMember attributes Signed-off-by: Whit Waldo <[email protected]> * Added JSON converter to new enum for Dapr Conversation role Signed-off-by: Whit Waldo <[email protected]> * Set up role to map to the string used in grpc call to sidecar Signed-off-by: Whit Waldo <[email protected]> * No need for the JSON converter after all Signed-off-by: Whit Waldo <[email protected]> * Added missing package version to fix build error Signed-off-by: Whit Waldo <[email protected]> * Removed duplicate using statement breaking build Signed-off-by: Whit Waldo <[email protected]> * Fixed missing [Fact] annotation Signed-off-by: Whit Waldo <[email protected]> * Updated proto types to reflect type name changes in dapr/dapr#8250 Signed-off-by: Whit Waldo <[email protected]> * Added support for service lifetime Signed-off-by: Whit Waldo <[email protected]> * Building out documentation for Dapr AI Signed-off-by: Whit Waldo <[email protected]> * Simplified registration Signed-off-by: Whit Waldo <[email protected]> * Tweaked package version Signed-off-by: Whit Waldo <[email protected]> * Using IConfiguration to source DaprClient values if provided in service provider Signed-off-by: Whit Waldo <[email protected]> * Removed Models.* directories, flattened into Conversation namespace Signed-off-by: Whit Waldo <[email protected]> * Swapped out to use IReadOnlyDictionary Signed-off-by: Whit Waldo <[email protected]> * Added suggested optimization Signed-off-by: Whit Waldo <[email protected]> * Fixed bad using statement Signed-off-by: Whit Waldo <[email protected]> * Updates to use uniform method for standing up new Dapr clients Signed-off-by: Whit Waldo <[email protected]> * Removed duplicate project reference Signed-off-by: Whit Waldo <[email protected]> * Fixed build error Signed-off-by: Whit Waldo <[email protected]> * Fixing build errors Signed-off-by: Whit Waldo <[email protected]> * Fixed bad references Signed-off-by: Whit Waldo <[email protected]> * Fixed several build errors Signed-off-by: Whit Waldo <[email protected]> * Fixing more build errors Signed-off-by: Whit Waldo <[email protected]> * Updated to fix several build errors Signed-off-by: Whit Waldo <[email protected]> * Fixed bad refernce Signed-off-by: Whit Waldo <[email protected]> * Fixing more build errors Signed-off-by: Whit Waldo <[email protected]> * Role is required when submitting conversation input Signed-off-by: Whit Waldo <[email protected]> * Removed impossible path since the role cannot be nullable Signed-off-by: Whit Waldo <[email protected]> * Removed impossible path from logic now that role cannot be null Signed-off-by: Whit Waldo <[email protected]> --------- Signed-off-by: Whit Waldo <[email protected]>
1 parent cfd4fbe commit 7b5ca4f

File tree

44 files changed

+3165
-2112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3165
-2112
lines changed

Directory.Packages.props

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
<Project>
2-
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
5-
</PropertyGroup>
6-
<ItemGroup>
7-
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
8-
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
9-
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
10-
<PackageVersion Include="FluentAssertions" Version="5.9.0" />
11-
<PackageVersion Include="GitHubActionsTestLogger" Version="1.1.2" />
12-
<PackageVersion Include="Google.Api.CommonProtos" Version="2.2.0" />
13-
<PackageVersion Include="Google.Protobuf" Version="3.28.2" />
14-
<PackageVersion Include="Grpc.AspNetCore" Version="2.66.0" />
15-
<PackageVersion Include="Grpc.Core.Testing" Version="2.46.6" />
16-
<PackageVersion Include="Grpc.Net.Client" Version="2.66.0" />
17-
<PackageVersion Include="Grpc.Net.ClientFactory" Version="2.66.0" />
18-
<PackageVersion Include="Grpc.Tools" Version="2.67.0" />
19-
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.35" />
20-
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.35" />
21-
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
22-
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
23-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
24-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
25-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.2" />
26-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
27-
<PackageVersion Include="Microsoft.DurableTask.Client.Grpc" Version="1.3.0" />
28-
<PackageVersion Include="Microsoft.DurableTask.Worker.Grpc" Version="1.3.0" />
29-
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
30-
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
31-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
32-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
33-
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
34-
<PackageVersion Include="Microsoft.Extensions.Http" Version="6.0.0" />
35-
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
36-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
37-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
38-
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
39-
<PackageVersion Include="MinVer" Version="2.3.0" />
40-
<PackageVersion Include="Moq" Version="4.20.72" />
41-
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
42-
<PackageVersion Include="protobuf-net.Grpc.AspNetCore" Version="1.2.2" />
43-
<PackageVersion Include="Serilog.AspNetCore" Version="6.1.0" />
44-
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
45-
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
46-
<PackageVersion Include="System.Formats.Asn1" Version="6.0.1" />
47-
<PackageVersion Include="System.Text.Json" Version="6.0.10" />
48-
<PackageVersion Include="xunit" Version="2.9.2" />
49-
<PackageVersion Include="xunit.extensibility.core" Version="2.9.2" />
50-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
51-
</ItemGroup>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
8+
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
9+
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
10+
<PackageVersion Include="FluentAssertions" Version="5.9.0" />
11+
<PackageVersion Include="GitHubActionsTestLogger" Version="1.1.2" />
12+
<PackageVersion Include="Google.Api.CommonProtos" Version="2.2.0" />
13+
<PackageVersion Include="Google.Protobuf" Version="3.28.2" />
14+
<PackageVersion Include="Grpc.AspNetCore" Version="2.66.0" />
15+
<PackageVersion Include="Grpc.Core.Testing" Version="2.46.6" />
16+
<PackageVersion Include="Grpc.Net.Client" Version="2.66.0" />
17+
<PackageVersion Include="Grpc.Net.ClientFactory" Version="2.66.0" />
18+
<PackageVersion Include="Grpc.Tools" Version="2.67.0" />
19+
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.35" />
20+
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.35" />
21+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
22+
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
23+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
24+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
25+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.2" />
26+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
27+
<PackageVersion Include="Microsoft.DurableTask.Client.Grpc" Version="1.3.0" />
28+
<PackageVersion Include="Microsoft.DurableTask.Worker.Grpc" Version="1.3.0" />
29+
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
30+
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
31+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
32+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
33+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="6.0.0" />
34+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
35+
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
36+
<PackageVersion Include="Microsoft.Extensions.Http" Version="6.0.0" />
37+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
38+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
39+
<PackageVersion Include="MinVer" Version="2.3.0" />
40+
<PackageVersion Include="Moq" Version="4.20.72" />
41+
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
42+
<PackageVersion Include="protobuf-net.Grpc.AspNetCore" Version="1.2.2" />
43+
<PackageVersion Include="Serilog.AspNetCore" Version="6.1.0" />
44+
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
45+
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
46+
<PackageVersion Include="System.Formats.Asn1" Version="6.0.1" />
47+
<PackageVersion Include="System.Text.Json" Version="6.0.10" />
48+
<PackageVersion Include="xunit" Version="2.9.2" />
49+
<PackageVersion Include="xunit.extensibility.core" Version="2.9.2" />
50+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
51+
</ItemGroup>
5252
</Project>

all.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Common", "src\Dapr.Com
119119
EndProject
120120
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Common.Test", "test\Dapr.Common.Test\Dapr.Common.Test.csproj", "{CDB47863-BEBD-4841-A807-46D868962521}"
121121
EndProject
122+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.AI", "src\Dapr.AI\Dapr.AI.csproj", "{273F2527-1658-4CCF-8DC6-600E921188C5}"
123+
EndProject
124+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.AI.Test", "test\Dapr.AI.Test\Dapr.AI.Test.csproj", "{2F3700EF-1CDA-4C15-AC88-360230000ECD}"
125+
EndProject
126+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AI", "AI", "{3046DBF4-C2FF-4F3A-9176-E1C01E0A90E5}"
127+
EndProject
128+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConversationalAI", "examples\AI\ConversationalAI\ConversationalAI.csproj", "{11011FF8-77EA-4B25-96C0-29D4D486EF1C}"
129+
EndProject
122130
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowExternalInteraction", "examples\Workflow\WorkflowExternalInteraction\WorkflowExternalInteraction.csproj", "{43CB06A9-7E88-4C5F-BFB8-947E072CBC9F}"
123131
EndProject
124132
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowMonitor", "examples\Workflow\WorkflowMonitor\WorkflowMonitor.csproj", "{7F73A3D8-FFC2-4E31-AA3D-A4840316A8C6}"
@@ -331,6 +339,18 @@ Global
331339
{CDB47863-BEBD-4841-A807-46D868962521}.Debug|Any CPU.Build.0 = Debug|Any CPU
332340
{CDB47863-BEBD-4841-A807-46D868962521}.Release|Any CPU.ActiveCfg = Release|Any CPU
333341
{CDB47863-BEBD-4841-A807-46D868962521}.Release|Any CPU.Build.0 = Release|Any CPU
342+
{273F2527-1658-4CCF-8DC6-600E921188C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
343+
{273F2527-1658-4CCF-8DC6-600E921188C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
344+
{273F2527-1658-4CCF-8DC6-600E921188C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
345+
{273F2527-1658-4CCF-8DC6-600E921188C5}.Release|Any CPU.Build.0 = Release|Any CPU
346+
{2F3700EF-1CDA-4C15-AC88-360230000ECD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
347+
{2F3700EF-1CDA-4C15-AC88-360230000ECD}.Debug|Any CPU.Build.0 = Debug|Any CPU
348+
{2F3700EF-1CDA-4C15-AC88-360230000ECD}.Release|Any CPU.ActiveCfg = Release|Any CPU
349+
{2F3700EF-1CDA-4C15-AC88-360230000ECD}.Release|Any CPU.Build.0 = Release|Any CPU
350+
{11011FF8-77EA-4B25-96C0-29D4D486EF1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
351+
{11011FF8-77EA-4B25-96C0-29D4D486EF1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
352+
{11011FF8-77EA-4B25-96C0-29D4D486EF1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
353+
{11011FF8-77EA-4B25-96C0-29D4D486EF1C}.Release|Any CPU.Build.0 = Release|Any CPU
334354
{43CB06A9-7E88-4C5F-BFB8-947E072CBC9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
335355
{43CB06A9-7E88-4C5F-BFB8-947E072CBC9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
336356
{43CB06A9-7E88-4C5F-BFB8-947E072CBC9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -439,6 +459,10 @@ Global
439459
{DFBABB04-50E9-42F6-B470-310E1B545638} = {27C5D71D-0721-4221-9286-B94AB07B58CF}
440460
{B445B19C-A925-4873-8CB7-8317898B6970} = {27C5D71D-0721-4221-9286-B94AB07B58CF}
441461
{CDB47863-BEBD-4841-A807-46D868962521} = {DD020B34-460F-455F-8D17-CF4A949F100B}
462+
{273F2527-1658-4CCF-8DC6-600E921188C5} = {27C5D71D-0721-4221-9286-B94AB07B58CF}
463+
{2F3700EF-1CDA-4C15-AC88-360230000ECD} = {DD020B34-460F-455F-8D17-CF4A949F100B}
464+
{3046DBF4-C2FF-4F3A-9176-E1C01E0A90E5} = {D687DDC4-66C5-4667-9E3A-FD8B78ECAA78}
465+
{11011FF8-77EA-4B25-96C0-29D4D486EF1C} = {3046DBF4-C2FF-4F3A-9176-E1C01E0A90E5}
442466
{43CB06A9-7E88-4C5F-BFB8-947E072CBC9F} = {BF3ED6BF-ADF3-4D25-8E89-02FB8D945CA9}
443467
{7F73A3D8-FFC2-4E31-AA3D-A4840316A8C6} = {BF3ED6BF-ADF3-4D25-8E89-02FB8D945CA9}
444468
{945DD3B7-94E5-435E-B3CB-796C20A652C7} = {BF3ED6BF-ADF3-4D25-8E89-02FB8D945CA9}

daprdocs/content/en/dotnet-sdk-docs/_index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ Put the Dapr .NET SDK to the test. Walk through the .NET quickstarts and tutoria
8484
<a href="{{< ref dotnet-jobs >}}" class="stretched-link"></a>
8585
</div>
8686
</div>
87+
<div class="card">
88+
<div class="card-body">
89+
<h5 class="card-title"><b>AI</b></h5>
90+
<p class="card-text">Create and manage AI operations in .NET</p>
91+
<a href="{{< ref dotnet-ai >}}" class="stretched-link"></a>
92+
</div>
93+
</div>
8794
</div>
8895

8996
## More information
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
_index.md
2+
3+
---
4+
type: docs
5+
title: "Getting started with the Dapr AI .NET SDK client"
6+
linkTitle: "AI"
7+
weight: 10000
8+
description: How to get up and running with the Dapr AI .NET SDK
9+
no_list: true
10+
---
11+
12+
The Dapr AI client package allows you to interact with the AI capabilities provided by the Dapr sidecar.
13+
14+
## Installation
15+
16+
To get started with the Dapr AI .NET SDK client, install the following package from NuGet:
17+
```sh
18+
dotnet add package Dapr.AI
19+
```
20+
21+
A `DaprConversationClient` holes access to networking resources in the form of TCP sockets used to communicate with the Dapr sidecar.
22+
23+
### Dependency Injection
24+
25+
The `AddDaprAiConversation()` method will register the Dapr client ASP.NET Core dependency injection and is the recommended approach
26+
for using this package. This method accepts an optional options delegate for configuring the `DaprConversationClient` and a
27+
`ServiceLifetime` argument, allowing you to specify a different lifetime for the registered services instead of the default `Singleton`
28+
value.
29+
30+
The following example assumes all default values are acceptable and is sufficient to register the `DaprConversationClient`:
31+
32+
```csharp
33+
services.AddDaprAiConversation();
34+
```
35+
36+
The optional configuration delegate is used to configure the `DaprConversationClient` by specifying options on the
37+
`DaprConversationClientBuilder` as in the following example:
38+
```csharp
39+
services.AddSingleton<DefaultOptionsProvider>();
40+
services.AddDaprAiConversation((serviceProvider, clientBuilder) => {
41+
//Inject a service to source a value from
42+
var optionsProvider = serviceProvider.GetRequiredService<DefaultOptionsProvider>();
43+
var standardTimeout = optionsProvider.GetStandardTimeout();
44+
45+
//Configure the value on the client builder
46+
clientBuilder.UseTimeout(standardTimeout);
47+
});
48+
```
49+
50+
### Manual Instantiation
51+
Rather than using dependency injection, a `DaprConversationClient` can also be built using the static client builder.
52+
53+
For best performance, create a single long-lived instance of `DaprConversationClient` and provide access to that shared instance throughout
54+
your application. `DaprConversationClient` instances are thread-safe and intended to be shared.
55+
56+
Avoid creating a `DaprConversationClient` per-operation.
57+
58+
A `DaprConversationClient` can be configured by invoking methods on the `DaprConversationClientBuilder` class before calling `.Build()`
59+
to create the client. The settings for each `DaprConversationClient` are separate and cannot be changed after calling `.Build()`.
60+
61+
```csharp
62+
var daprConversationClient = new DaprConversationClientBuilder()
63+
.UseJsonSerializerSettings( ... ) //Configure JSON serializer
64+
.Build();
65+
```
66+
67+
See the .NET [documentation here]({{< ref dotnet-client >}}) for more information about the options available when configuring the Dapr client via the builder.
68+
69+
## Try it out
70+
Put the Dapr AI .NET SDK to the test. Walk through the samples to see Dapr in action:
71+
72+
| SDK Samples | Description |
73+
| ----------- | ----------- |
74+
| [SDK samples](https://github.com/dapr/dotnet-sdk/tree/master/examples) | Clone the SDK repo to try out some examples and get started. |
75+
76+
## Building Blocks
77+
78+
This part of the .NET SDK allows you to interface with the Conversations API to send and receive messages from
79+
large language models.
80+
81+
### Send messages
82+
83+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
type: docs
3+
title: "Best practices with the Dapr AI .NET SDK client"
4+
linkTitle: "Best Practices"
5+
weight: 100000
6+
description: How to get up and running with the Dapr .NET SDK
7+
---
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\..\src\Dapr.AI\Dapr.AI.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Dapr.AI.Conversation;
2+
using Dapr.AI.Conversation.Extensions;
3+
4+
var builder = WebApplication.CreateBuilder(args);
5+
6+
builder.Services.AddDaprAiConversation();
7+
8+
var app = builder.Build();
9+
10+
var conversationClient = app.Services.GetRequiredService<DaprConversationClient>();
11+
var response = await conversationClient.ConverseAsync("conversation",
12+
new List<DaprConversationInput>
13+
{
14+
new DaprConversationInput(
15+
"Please write a witty haiku about the Dapr distributed programming framework at dapr.io",
16+
DaprConversationRole.Generic)
17+
});
18+
19+
Console.WriteLine("Received the following from the LLM:");
20+
foreach (var resp in response.Outputs)
21+
{
22+
Console.WriteLine($"\t{resp.Result}");
23+
}

src/Dapr.AI/AssemblyInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Dapr.AI.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1f597635c44597fcecb493e2b1327033b29b1a98ac956a1a538664b68f87d45fbaada0438a15a6265e62864947cc067d8da3a7d93c5eb2fcbb850e396c8684dba74ea477d82a1bbb18932c0efb30b64ff1677f85ae833818707ac8b49ad8062ca01d2c89d8ab1843ae73e8ba9649cd28666b539444dcdee3639f95e2a099bb2")]
4+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ------------------------------------------------------------------------
2+
// Copyright 2024 The Dapr Authors
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
// ------------------------------------------------------------------------
13+
14+
using Google.Protobuf.WellKnownTypes;
15+
16+
namespace Dapr.AI.Conversation;
17+
18+
/// <summary>
19+
/// Options used to configure the conversation operation.
20+
/// </summary>
21+
/// <param name="ConversationId">The identifier of the conversation this is a continuation of.</param>
22+
public sealed record ConversationOptions(string? ConversationId = null)
23+
{
24+
/// <summary>
25+
/// Temperature for the LLM to optimize for creativity or predictability.
26+
/// </summary>
27+
public double Temperature { get; init; } = default;
28+
/// <summary>
29+
/// Flag that indicates whether data that comes back from the LLM should be scrubbed of PII data.
30+
/// </summary>
31+
public bool ScrubPII { get; init; } = default;
32+
/// <summary>
33+
/// The metadata passing to the conversation components.
34+
/// </summary>
35+
public IReadOnlyDictionary<string, string> Metadata { get; init; } = new Dictionary<string, string>();
36+
/// <summary>
37+
/// Parameters for all custom fields.
38+
/// </summary>
39+
public IReadOnlyDictionary<string, Any> Parameters { get; init; } = new Dictionary<string, Any>();
40+
}

0 commit comments

Comments
 (0)