Skip to content

Commit

Permalink
Merge pull request dapr#4462 from hhunter-ms/issue_4374-2
Browse files Browse the repository at this point in the history
[Conversation] Finish how-to
  • Loading branch information
hhunter-ms authored Jan 6, 2025
2 parents 5dd13ad + ebecf62 commit 088e980
Showing 1 changed file with 104 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Let's get started using the [conversation API]({{< ref conversation-overview.md

- Set up one of the available Dapr components (echo) that work with the conversation API.
- Add the conversation client to your application.
- Run the connection using `dapr run`.

## Set up the conversation component

Expand All @@ -35,15 +36,38 @@ spec:
## Connect the conversation client
The following examples use an HTTP client to send a POST request to Dapr's sidecar HTTP endpoint. You can also use [the Dapr SDK client instead]({{< ref "#related-links" >}}).
{{< tabs ".NET" "Go" "Rust" >}}
<!-- .NET -->
{{% codetab %}}
```dotnet
todo
```csharp
using Dapr.AI.Conversation;
using Dapr.AI.Conversation.Extensions;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDaprConversationClient();

var app = builder.Build();

var conversationClient = app.Services.GetRequiredService<DaprConversationClient>();
var response = await conversationClient.ConverseAsync("conversation",
new List<DaprConversationInput>
{
new DaprConversationInput(
"Please write a witty haiku about the Dapr distributed programming framework at dapr.io",
DaprConversationRole.Generic)
});

Console.WriteLine("Received the following from the LLM:");
foreach (var resp in response.Outputs)
{
Console.WriteLine($"\t{resp.Result}");
}
```

{{% /codetab %}}
Expand Down Expand Up @@ -130,6 +154,84 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

{{< /tabs >}}

## Run the conversation connection

Start the connection using the `dapr run` command. For example, for this scenario, we're running `dapr run` on an application with the app ID `conversation` and pointing to our conversation YAML file in the `./config` directory.

{{< tabs ".NET" "Go" "Rust" >}}

<!-- .NET -->
{{% codetab %}}

```bash
dapr run --app-id conversation --dapr-grpc-port 50001 --log-level debug --resources-path ./config -- dotnet run
```

{{% /codetab %}}

<!-- Go -->
{{% codetab %}}

```bash
dapr run --app-id conversation --dapr-grpc-port 50001 --log-level debug --resources-path ./config -- go run ./main.go
```

**Expected output**

```
- '== APP == conversation output: hello world'
```

{{% /codetab %}}

<!-- Rust -->
{{% codetab %}}

```bash
dapr run --app-id=conversation --resources-path ./config --dapr-grpc-port 3500 -- cargo run --example conversation
```

**Expected output**

```
- 'conversation input: hello world'
- 'conversation output: hello world'
```

{{% /codetab %}}

{{< /tabs >}}

## Related links

Try out the conversation API using the full examples provided in the supported SDK repos.


{{< tabs ".NET" "Go" "Rust" >}}

<!-- .NET -->
{{% codetab %}}

[Dapr conversation example with the .NET SDK](https://github.com/dapr/dotnet-sdk/tree/master/examples/AI/ConversationalAI)

{{% /codetab %}}

<!-- Go -->
{{% codetab %}}

[Dapr conversation example with the Go SDK](https://github.com/dapr/go-sdk/tree/main/examples/conversation)

{{% /codetab %}}

<!-- Rust -->
{{% codetab %}}

[Dapr conversation example with the Rust SDK](https://github.com/dapr/rust-sdk/tree/main/examples/src/conversation)

{{% /codetab %}}

{{< /tabs >}}


## Next steps

Expand Down

0 comments on commit 088e980

Please sign in to comment.