-
Notifications
You must be signed in to change notification settings - Fork 211
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
75f487f
88fe015
c27d3ab
ca2dd02
fada33f
d14ce3e
842b0e7
c18ccf5
a169d00
dd44b79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} | ||
} |
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> | ||
<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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
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); | ||
} |
There was a problem hiding this comment.
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
? asai
is too genericThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to conversation