Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
[submodule "sdkdocs/go"]
path = sdkdocs/go
url = https://github.com/dapr/go-sdk.git
[submodule "sdkdocs/java"]
path = sdkdocs/java
url = https://github.com/dapr/java-sdk.git
[submodule "sdkdocs/js"]
path = sdkdocs/js
url = https://github.com/dapr/js-sdk.git
Expand Down
4 changes: 2 additions & 2 deletions hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ module:
- source: sdkdocs/go/daprdocs/content/en/go-sdk-contributing
target: content/contributing/sdk-contrib/
lang: en
- source: sdkdocs/java/daprdocs/content/en/java-sdk-docs
- source: sdkdocs/java/content/en/java-sdk-docs
target: content/developing-applications/sdks/java
lang: en
- source: sdkdocs/java/daprdocs/content/en/java-sdk-contributing
- source: sdkdocs/java/content/en/java-sdk-contributing
target: content/contributing/sdk-contrib/
lang: en
- source: sdkdocs/js/daprdocs/content/en/js-sdk-docs
Expand Down
1 change: 0 additions & 1 deletion sdkdocs/java
Submodule java deleted from 3bb91e
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
type: docs
title: "Contributing to the Java SDK"
linkTitle: "Java SDK"
weight: 3000
description: Guidelines for contributing to the Dapr Java SDK
---

When contributing to the [Java SDK](https://github.com/dapr/java-sdk) the following rules and best-practices should be followed.

## Examples

The `examples` directory contains code samples for users to run to try out specific functionality of the various Java SDK packages and extensions. When writing new and updated samples keep in mind:

- All examples should be runnable on Windows, Linux, and MacOS. While Java code is consistent among operating systems, any pre/post example commands should provide options through [tabpane]({{% ref "contributing-docs.md#tabbed-content" %}})
- Contain steps to download/install any required pre-requisites. Someone coming in with a fresh OS install should be able to start on the example and complete it without an error. Links to external download pages are fine.

## Docs

The `daprdocs` directory contains the markdown files that are rendered into the [Dapr Docs](https://docs.dapr.io) website. When the documentation website is built, this repo is cloned and configured so that its contents are rendered with the docs content. When writing docs, keep in mind:

- All rules in the [docs guide]({{% ref contributing-docs.md %}}) should be followed in addition to these.
- All files and directories should be prefixed with `java-` to ensure all file/directory names are globally unique across all Dapr documentation.

## Github Dapr Bot Commands

Checkout the [daprbot documentation](https://docs.dapr.io/contributing/daprbot/) for Github commands you can run in this repo for common tasks. For example, you can run the `/assign` (as a comment on an issue) to assign the issue to yourself.
145 changes: 145 additions & 0 deletions sdkdocs/java/content/en/java-sdk-docs/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
type: docs
title: "Dapr Java SDK"
linkTitle: "Java"
weight: 1000
description: Java SDK packages for developing Dapr applications
cascade:
github_repo: https://github.com/dapr/java-sdk
github_subdir: daprdocs/content/en/java-sdk-docs
path_base_for_github_subdir: content/en/developing-applications/sdks/java/
github_branch: master
---

Dapr offers a variety of packages to help with the development of Java applications. Using them you can create Java clients, servers, and virtual actors with Dapr.

## Prerequisites

- [Dapr CLI]({{% ref install-dapr-cli.md %}}) installed
- Initialized [Dapr environment]({{% ref install-dapr-selfhost.md %}})
- JDK 11 or above - the published jars are compatible with Java 8:
- [AdoptOpenJDK 11 - LTS](https://adoptopenjdk.net/)
- [Oracle's JDK 15](https://www.oracle.com/java/technologies/javase-downloads.html)
- [Oracle's JDK 11 - LTS](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html)
- [OpenJDK](https://openjdk.java.net/)
- Install one of the following build tools for Java:
- [Maven 3.x](https://maven.apache.org/install.html)
- [Gradle 6.x](https://gradle.org/install/)

## Import Dapr's Java SDK

Next, import the Java SDK packages to get started. Select your preferred build tool to learn how to import.

{{< tabpane text=true >}}

{{% tab header="Maven" %}}
<!--Maven-->

For a Maven project, add the following to your `pom.xml` file:

```xml
<project>
...
<dependencies>
...
<!-- Dapr's core SDK with all features, except Actors. -->
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk</artifactId>
<version>1.16.0</version>
</dependency>
<!-- Dapr's SDK for Actors (optional). -->
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-actors</artifactId>
<version>1.16.0</version>
</dependency>
<!-- Dapr's SDK integration with SpringBoot (optional). -->
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-springboot</artifactId>
<version>1.16.0</version>
</dependency>
...
</dependencies>
...
</project>
```
{{% /tab %}}

{{% tab header="Gradle" %}}
<!--Gradle-->

For a Gradle project, add the following to your `build.gradle` file:

```java
dependencies {
...
// Dapr's core SDK with all features, except Actors.
compile('io.dapr:dapr-sdk:1.16.0')
// Dapr's SDK for Actors (optional).
compile('io.dapr:dapr-sdk-actors:1.16.0')
// Dapr's SDK integration with SpringBoot (optional).
compile('io.dapr:dapr-sdk-springboot:1.16.0')
}
```

{{% /tab %}}

{{< /tabpane >}}

If you are also using Spring Boot, you may run into a common issue where the `OkHttp` version that the Dapr SDK uses conflicts with the one specified in the Spring Boot _Bill of Materials_.

You can fix this by specifying a compatible `OkHttp` version in your project to match the version that the Dapr SDK uses:

```xml
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>1.16.0</version>
</dependency>
```

## Try it out

Put the Dapr Java SDK to the test. Walk through the Java quickstarts and tutorials to see Dapr in action:

| SDK samples | Description |
| ----------- | ----------- |
| [Quickstarts]({{% ref quickstarts %}}) | Experience Dapr's API building blocks in just a few minutes using the Java SDK. |
| [SDK samples](https://github.com/dapr/java-sdk/tree/master/examples) | Clone the SDK repo to try out some examples and get started. |

```java
import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;

try (DaprClient client = (new DaprClientBuilder()).build()) {
// sending a class with message; BINDING_OPERATION="create"
client.invokeBinding(BINDING_NAME, BINDING_OPERATION, myClass).block();

// sending a plain string
client.invokeBinding(BINDING_NAME, BINDING_OPERATION, message).block();
}
```

- For a full guide on output bindings visit [How-To: Output bindings]({{% ref howto-bindings.md %}}).
- Visit [Java SDK examples](https://github.com/dapr/java-sdk/tree/master/examples/src/main/java/io/dapr/examples/bindings/http) for code samples and instructions to try out output bindings.

## Available packages

<div class="card-deck">
<div class="card">
<div class="card-body">
<h5 class="card-title"><b>Client</b></h5>
<p class="card-text">Create Java clients that interact with a Dapr sidecar and other Dapr applications.</p>
<a href="{{% ref java-client %}}" class="stretched-link"></a>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title"><b>Workflow</b></h5>
<p class="card-text">Create and manage workflows that work with other Dapr APIs in Java.</p>
<a href="{{% ref workflow %}}" class="stretched-link"></a>
</div>
</div>
</div>
7 changes: 7 additions & 0 deletions sdkdocs/java/content/en/java-sdk-docs/java-ai/_index.md
Original file line number Diff line number Diff line change
@@ -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.
---
105 changes: 105 additions & 0 deletions sdkdocs/java/content/en/java-sdk-docs/java-ai/java-ai-howto.md
Original file line number Diff line number Diff line change
@@ -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 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).

## 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<ConversationResponse> 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 <ISBN>
```

As shown in the output, the number sent to the API is obfuscated and returned in the form of <ISBN>.
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 %}})
Loading
Loading