From bb56b8d8a815699b1750d1fc116ab6b68dbe1ac6 Mon Sep 17 00:00:00 2001 From: Siri Varma Vegiraju Date: Tue, 29 Apr 2025 06:27:02 -0700 Subject: [PATCH 1/3] Update CONTRIBUTING.md Signed-off-by: Siri Varma Vegiraju --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4009213b11..c094f92fa1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,6 +51,11 @@ Before you file an issue, make sure you've checked the following: This section describes the guidelines for contributing code / docs to Dapr. +### Things to consider when adding new API to SDK + +1. All the new API's go under [dapr-sdk maven package](https://github.com/dapr/java-sdk/tree/master/sdk) +2. Make sure there is an example talking about how to use the API along with a README. [Example](https://github.com/dapr/java-sdk/pull/1235/files#diff-69ed756c4c01fd5fa884aac030dccb8f3f4d4fefa0dc330862d55a6f87b34a14) + ### Pull Requests All contributions come through pull requests. To submit a proposed change, we recommend following this workflow: @@ -64,6 +69,7 @@ All contributions come through pull requests. To submit a proposed change, we re 6. Commit and open a PR 7. Wait for the CI process to finish and make sure all checks are green 8. A maintainer of the project will be assigned, and you can expect a review within a few days +9. All the files have the Copyright header. ### Configure the code style with checkstyle From 95416fd4c66e7f293e07157771c19e90f4340c88 Mon Sep 17 00:00:00 2001 From: sirivarma Date: Mon, 26 May 2025 21:51:01 -0700 Subject: [PATCH 2/3] Add conversation ai example Signed-off-by: sirivarma --- .../en/java-sdk-docs/java-ai/_index.md | 7 ++ .../en/java-sdk-docs/java-ai/java-ai-howto.md | 105 ++++++++++++++++++ .../java-jobs/java-jobs-howto.md | 2 +- 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 daprdocs/content/en/java-sdk-docs/java-ai/_index.md create mode 100644 daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md diff --git a/daprdocs/content/en/java-sdk-docs/java-ai/_index.md b/daprdocs/content/en/java-sdk-docs/java-ai/_index.md new file mode 100644 index 0000000000..f0543de56f --- /dev/null +++ b/daprdocs/content/en/java-sdk-docs/java-ai/_index.md @@ -0,0 +1,7 @@ +--- +type: docs +title: "AI" +linkTitle: "AI" +weight: 3000 +description: With the Dapr Conversation AI package, you can interact with the Dapr AI workloads from a Java application. To get started, walk through the [Dapr AI]({{< ref java-ai-howto.md >}}) how-to guide. +--- \ No newline at end of file diff --git a/daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md b/daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md new file mode 100644 index 0000000000..cc851c107a --- /dev/null +++ b/daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md @@ -0,0 +1,105 @@ +--- +type: docs +title: "How to: Author and manage Dapr Conversation AI in the Java SDK" +linkTitle: "How to: Author and manage Conversation AI" +weight: 20000 +description: How to get up and running with Conversation AI using the Dapr Java SDK +--- + +As part of this demonstration, we will look at how to use the Conversation API to converse with a Large Language Model (LLM). The API +will return the response from the LLM for the given prompt. With the [provided conversation ai example](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/conversation), you will: + +- You will provide a prompt [Conversation AI example](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/conversation/DemoConversationAI.java) +- Filter out Personally identifiable information (PII). + +This example uses the default configuration from `dapr init` in [self-hosted mode](https://github.com/dapr/cli#install-dapr-on-your-local-machine-self-hosted). + +## Prerequisites + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- Java JDK 11 (or greater): + - [Oracle JDK](https://www.oracle.com/java/technologies/downloads), or + - OpenJDK +- [Apache Maven](https://maven.apache.org/install.html), version 3.x. +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + +## Set up the environment + +Clone the [Java SDK repo](https://github.com/dapr/java-sdk) and navigate into it. + +```bash +git clone https://github.com/dapr/java-sdk.git +cd java-sdk +``` + +Run the following command to install the requirements for running the Conversation AI example with the Dapr Java SDK. + +```bash +mvn clean install -DskipTests +``` + +From the Java SDK root directory, navigate to the examples' directory. + +```bash +cd examples +``` + +Run the Dapr sidecar. + +```sh +dapr run --app-id conversationapp --dapr-grpc-port 51439 --dapr-http-port 3500 --app-port 8080 +``` + +> Now, Dapr is listening for HTTP requests at `http://localhost:3500` and gRPC requests at `http://localhost:51439`. + +## Send a prompt with Personally identifiable information (PII) to the Conversation AI API + +In the `DemoConversationAI` there are steps to send a prompt using the `converse` method under the `DaprPreviewClient`. + +```java +public class DemoConversationAI { + /** + * The main method to start the client. + * + * @param args Input arguments (unused). + */ + public static void main(String[] args) { + try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) { + System.out.println("Sending the following input to LLM: Hello How are you? This is the my number 672-123-4567"); + + ConversationInput daprConversationInput = new ConversationInput("Hello How are you? " + + "This is the my number 672-123-4567"); + + // Component name is the name provided in the metadata block of the conversation.yaml file. + Mono responseMono = client.converse(new ConversationRequest("echo", + List.of(daprConversationInput)) + .setContextId("contextId") + .setScrubPii(true).setTemperature(1.1d)); + ConversationResponse response = responseMono.block(); + System.out.printf("Conversation output: %s", response.getConversationOutputs().get(0).getResult()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} +``` + +Run the `DemoConversationAI` with the following command. + +```sh +java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.conversation.DemoConversationAI +``` + +### Sample output +``` +== APP == Conversation output: Hello How are you? This is the my number +``` + +As shown in the output, the number sent to the API is obfuscated and returned in the form of . +The example above uses an ["echo"](https://docs.dapr.io/developing-applications/building-blocks/conversation/howto-conversation-layer/#set-up-the-conversation-component) +component for testing, which simply returns the input message. +When integrated with LLMs like OpenAI or Claude, you’ll receive meaningful responses instead of echoed input. + +## Next steps +- [Learn more about Conversation AI]({{< ref conversation-overview.md >}}) +- [Conversation AI API reference]({{< ref conversation_api.md >}}) \ No newline at end of file diff --git a/daprdocs/content/en/java-sdk-docs/java-jobs/java-jobs-howto.md b/daprdocs/content/en/java-sdk-docs/java-jobs/java-jobs-howto.md index 1aa8f7b911..f68a2f8d59 100644 --- a/daprdocs/content/en/java-sdk-docs/java-jobs/java-jobs-howto.md +++ b/daprdocs/content/en/java-sdk-docs/java-jobs/java-jobs-howto.md @@ -38,7 +38,7 @@ Run the following command to install the requirements for running the jobs examp mvn clean install -DskipTests ``` -From the Java SDK root directory, navigate to the Dapr Jobs example. +From the Java SDK root directory, navigate to the examples' directory. ```bash cd examples From 133405f507e93a814edaf186c087ab5b4414ed48 Mon Sep 17 00:00:00 2001 From: sirivarma Date: Mon, 26 May 2025 21:54:18 -0700 Subject: [PATCH 3/3] Add conversation ai example Signed-off-by: sirivarma --- daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md b/daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md index cc851c107a..f28e28c3ac 100644 --- a/daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md +++ b/daprdocs/content/en/java-sdk-docs/java-ai/java-ai-howto.md @@ -9,7 +9,7 @@ description: How to get up and running with Conversation AI using the Dapr Java As part of this demonstration, we will look at how to use the Conversation API to converse with a Large Language Model (LLM). The API will return the response from the LLM for the given prompt. With the [provided conversation ai example](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/conversation), you will: -- You will provide a prompt [Conversation AI example](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/conversation/DemoConversationAI.java) +- You will provide a prompt using the [Conversation AI example](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/conversation/DemoConversationAI.java) - Filter out Personally identifiable information (PII). This example uses the default configuration from `dapr init` in [self-hosted mode](https://github.com/dapr/cli#install-dapr-on-your-local-machine-self-hosted).