Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Conversation AI to Java SDK #1235

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
<artifactId>dapr-sdk</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-ai</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.evanlennick</groupId>
<artifactId>retry4j</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.dapr.examples.conversation;

import io.dapr.ai.client.DaprConversationClient;
import io.dapr.ai.client.DaprConversationInput;
import io.dapr.ai.client.DaprConversationResponse;
import io.dapr.v1.DaprProtos;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.Collections;

public class DemoConversationAI {
/**
* The main method to start the client.
*
* @param args Input arguments (unused).
*/
public static void main(String[] args) {
try (DaprConversationClient client = new DaprConversationClient()) {
DaprConversationInput daprConversationInput = new DaprConversationInput("11");

// Component name is the name provided in the metadata block of the conversation.yaml file.
Mono<DaprConversationResponse> instanceId = client.converse("openai", new ArrayList<>(Collections.singleton(daprConversationInput)), "1234", false, 0.0d);
System.out.printf("Started a new chaining model workflow with instance ID: %s%n", instanceId);
DaprConversationResponse response = instanceId.block();

System.out.println(response);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<grpc.version>1.69.0</grpc.version>
<protobuf.version>3.25.5</protobuf.version>
<protocCommand>protoc</protocCommand>
<dapr.proto.baseurl>https://raw.githubusercontent.com/dapr/dapr/v1.14.4/dapr/proto</dapr.proto.baseurl>
<dapr.proto.baseurl>https://raw.githubusercontent.com/dapr/dapr/v1.15.2/dapr/proto</dapr.proto.baseurl>
<dapr.sdk.version>1.15.0-SNAPSHOT</dapr.sdk.version>
<dapr.sdk.alpha.version>0.15.0-SNAPSHOT</dapr.sdk.alpha.version>
<os-maven-plugin.version>1.7.1</os-maven-plugin.version>
Expand Down Expand Up @@ -338,6 +338,7 @@
<module>sdk-autogen</module>
<module>sdk</module>
<module>sdk-actors</module>
<module>sdk-ai</module>
<module>sdk-workflows</module>
<module>sdk-springboot</module>
<module>dapr-spring</module>
Expand Down
164 changes: 164 additions & 0 deletions sdk-ai/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<project
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-parent</artifactId>
<version>1.15.0-SNAPSHOT</version>
</parent>

<artifactId>dapr-sdk-ai</artifactId>
<packaging>jar</packaging>
<version>1.15.0-SNAPSHOT</version>
<name>dapr-sdk-ai</name>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siri-varma should we call it conversation? instead of ai? as ai is too generic

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to conversation

<description>SDK for AI on Dapr</description>

<properties>
<maven.deploy.skip>false</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>io.dapr</groupId>
<artifactId>dapr-sdk-autogen</artifactId>
<version>1.14.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft</groupId>
<artifactId>durabletask-client</artifactId>
<version>1.5.0</version>
</dependency>
<!--
manually declare durabletask-client's jackson dependencies
which conflict with dapr-sdk's jackson dependencies
https://github.com/microsoft/durabletask-java/blob/main/client/build.gradle#L16
-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
Copy link
Contributor

@salaboy salaboy Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siri-varma please include the nexus plugin as shown in here: https://github.com/dapr/java-sdk/blob/master/dapr-spring/pom.xml#L95

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the nexus plugin

<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>target/jacoco-report/</outputDirectory>
</configuration>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>80%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>

</executions>
</plugin>
</plugins>
</build>
</project>
40 changes: 40 additions & 0 deletions sdk-ai/src/main/java/io/dapr/ai/client/DaprAiClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.dapr.ai.client;

import reactor.core.publisher.Mono;

import javax.annotation.Nullable;
import java.util.List;

/**
* Defines client operations for managing Dapr AI instances.
*/
interface DaprAiClient {

/**
* Method to call the Dapr Converse API.
*
* @param conversationComponentName name for the conversation component.
* @param daprConversationInputs prompts that are part of the conversation.
* @param contextId identifier of an existing chat (like in ChatGPT)
* @param scrubPii data that comes from the LLM.
* @param temperature to optimize from creativity or predictability.
* @return @ConversationResponse.
*/
Mono<DaprConversationResponse> converse(
String conversationComponentName,
List<DaprConversationInput> daprConversationInputs,
String contextId,
boolean scrubPii,
double temperature);

/**
* Method to call the Dapr Converse API.
*
* @param conversationComponentName name for the conversation component.
* @param daprConversationInputs prompts that are part of the conversation.
* @return @ConversationResponse.
*/
Mono<DaprConversationResponse> converse(
String conversationComponentName,
List<DaprConversationInput> daprConversationInputs);
}
Loading