Skip to content

Commit c6c36de

Browse files
committed
Address comments
Signed-off-by: siri-varma <[email protected]>
1 parent fb795a6 commit c6c36de

File tree

11 files changed

+77
-112
lines changed

11 files changed

+77
-112
lines changed

examples/src/main/java/io/dapr/examples/conversation/DemoConversationAI.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
import io.dapr.client.domain.ConversationResponse;
2121
import reactor.core.publisher.Mono;
2222

23-
import java.util.ArrayList;
24-
import java.util.Collections;
23+
import java.util.List;
2524

2625
public class DemoConversationAI {
2726
/**
@@ -31,18 +30,20 @@ public class DemoConversationAI {
3130
*/
3231
public static void main(String[] args) {
3332
try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) {
33+
System.out.println("Sending the following input to LLM: Hello How are you? This is the my number 672-123-4567");
34+
3435
ConversationInput daprConversationInput = new ConversationInput("Hello How are you? "
35-
+ "This is the my number 672-123-4567");
36+
+ "This is the my number 672-123-4567");
3637

3738
// Component name is the name provided in the metadata block of the conversation.yaml file.
3839
Mono<ConversationResponse> responseMono = client.converse(new ConversationRequest("echo",
39-
new ArrayList<>(Collections.singleton(daprConversationInput)))
40-
.setContextId("contextId")
41-
.setScrubPii(true).setTemperature(1.1d));
40+
List.of(daprConversationInput))
41+
.setContextId("contextId")
42+
.setScrubPii(true).setTemperature(1.1d));
4243
ConversationResponse response = responseMono.block();
4344
System.out.printf("Conversation output: %s", response.getConversationOutpus().get(0).getResult());
4445
} catch (Exception e) {
4546
throw new RuntimeException(e);
4647
}
4748
}
48-
}
49+
}

examples/src/main/java/io/dapr/examples/conversation/README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Manage Dapr Jobs via the Conversation API
1+
## Manage Dapr via the Conversation API
22

3-
This example provides the different capabilities provided by Dapr Java SDK for Conversation. For further information about Job APIs please refer to [this link](https://docs.dapr.io/developing-applications/building-blocks/conversation/conversation-overview/)
3+
This example provides the different capabilities provided by Dapr Java SDK for Conversation. For further information about Conversation APIs please refer to [this link](https://docs.dapr.io/developing-applications/building-blocks/conversation/conversation-overview/)
44

55
### Using the Conversation API
66

@@ -57,14 +57,16 @@ public class DemoConversationAI {
5757
*/
5858
public static void main(String[] args) {
5959
try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) {
60+
System.out.println("Sending the following input to LLM: Hello How are you? This is the my number 672-123-4567");
61+
6062
ConversationInput daprConversationInput = new ConversationInput("Hello How are you? "
61-
+ "This is the my number 672-123-4567");
63+
+ "This is the my number 672-123-4567");
6264

6365
// Component name is the name provided in the metadata block of the conversation.yaml file.
6466
Mono<ConversationResponse> responseMono = client.converse(new ConversationRequest("echo",
65-
new ArrayList<>(Collections.singleton(daprConversationInput)))
66-
.setContextId("contextId")
67-
.setScrubPii(true).setTemperature(1.1d));
67+
List.of(daprConversationInput))
68+
.setContextId("contextId")
69+
.setScrubPii(true).setTemperature(1.1d));
6870
ConversationResponse response = responseMono.block();
6971
System.out.printf("Conversation output: %s", response.getConversationOutpus().get(0).getResult());
7072
} catch (Exception e) {

sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprConversationIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ public void testConversationSDKShouldScrubPIIOnlyForTheInputWhereScrubPIIIsSet()
128128
Assertions.assertEquals("input this <PHONE_NUMBER>",
129129
response.getConversationOutpus().get(1).getResult());
130130
}
131-
}
131+
}

sdk-tests/src/test/java/io/dapr/it/testcontainers/TestConversationApplication.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ public class TestConversationApplication {
2222
public static void main(String[] args) {
2323
SpringApplication.run(TestConversationApplication.class, args);
2424
}
25-
26-
}
25+
}

sdk-tests/src/test/java/io/dapr/it/testcontainers/TestDaprConversationConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ public DaprPreviewClient daprPreviewClient(
3838

3939
return new DaprClientBuilder().withPropertyOverrides(overrides).buildPreviewClient();
4040
}
41-
}
41+
}

sdk/src/main/java/io/dapr/client/DaprClientImpl.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
import java.io.IOException;
104104
import java.time.Duration;
105105
import java.time.Instant;
106-
import java.time.OffsetDateTime;
107106
import java.time.ZoneOffset;
108107
import java.time.format.DateTimeFormatter;
109108
import java.util.ArrayList;
@@ -1568,13 +1567,13 @@ public Mono<ConversationResponse> converse(ConversationRequest conversationReque
15681567
DaprProtos.ConversationRequest.Builder protosConversationRequestBuilder = DaprProtos.ConversationRequest
15691568
.newBuilder().setTemperature(conversationRequest.getTemperature())
15701569
.setScrubPII(conversationRequest.isScrubPii())
1571-
.setName(conversationRequest.getLlmName());
1570+
.setName(conversationRequest.getName());
15721571

15731572
if (conversationRequest.getContextId() != null) {
15741573
protosConversationRequestBuilder.setContextID(conversationRequest.getContextId());
15751574
}
15761575

1577-
for (ConversationInput input : conversationRequest.getConversationInputs()) {
1576+
for (ConversationInput input : conversationRequest.getInputs()) {
15781577
if (input.getContent() == null || input.getContent().isEmpty()) {
15791578
throw new IllegalArgumentException("Conversation input content cannot be null or empty.");
15801579
}
@@ -1619,12 +1618,12 @@ public Mono<ConversationResponse> converse(ConversationRequest conversationReque
16191618
}
16201619

16211620
private void validateConversationRequest(ConversationRequest conversationRequest) {
1622-
if ((conversationRequest.getLlmName() == null) || (conversationRequest.getLlmName().trim().isEmpty())) {
1621+
if ((conversationRequest.getName() == null) || (conversationRequest.getName().trim().isEmpty())) {
16231622
throw new IllegalArgumentException("LLM name cannot be null or empty.");
16241623
}
16251624

1626-
if ((conversationRequest.getConversationInputs() == null) || (conversationRequest
1627-
.getConversationInputs().isEmpty())) {
1625+
if ((conversationRequest.getInputs() == null) || (conversationRequest
1626+
.getInputs().isEmpty())) {
16281627
throw new IllegalArgumentException("Conversation inputs cannot be null or empty.");
16291628
}
16301629
}

sdk/src/main/java/io/dapr/client/domain/ConversationInput.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ConversationInput {
2020

2121
private final String content;
2222

23-
private ConversationRole role;
23+
private String role;
2424

2525
private boolean scrubPii;
2626

@@ -47,7 +47,7 @@ public String getContent() {
4747
*
4848
* @return this.
4949
*/
50-
public ConversationRole getRole() {
50+
public String getRole() {
5151
return role;
5252
}
5353

@@ -57,7 +57,7 @@ public ConversationRole getRole() {
5757
* @param role The role to assign to the message.
5858
* @return this.
5959
*/
60-
public ConversationInput setRole(ConversationRole role) {
60+
public ConversationInput setRole(String role) {
6161
this.role = role;
6262
return this;
6363
}

sdk/src/main/java/io/dapr/client/domain/ConversationRequest.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,40 @@
2121
*/
2222
public class ConversationRequest {
2323

24-
private final String llmName;
25-
private final List<ConversationInput> daprConversationInputs;
24+
private final String name;
25+
private final List<ConversationInput> inputs;
2626
private String contextId;
2727
private boolean scrubPii;
2828
private double temperature;
2929

3030
/**
3131
* Constructs a DaprConversation with a component name and conversation inputs.
3232
*
33-
* @param llmName The name of the LLM component. See a list of all available conversation components
33+
* @param name The name of the Dapr conversation component. See a list of all available conversation components
3434
* @see <a href="https://docs.dapr.io/reference/components-reference/supported-conversation/"></a>
35-
* @param conversationInputs the list of Dapr conversation inputs
35+
* @param inputs the list of Dapr conversation inputs
3636
*/
37-
public ConversationRequest(String llmName, List<ConversationInput> conversationInputs) {
38-
this.llmName = llmName;
39-
this.daprConversationInputs = conversationInputs;
37+
public ConversationRequest(String name, List<ConversationInput> inputs) {
38+
this.name = name;
39+
this.inputs = inputs;
4040
}
4141

4242
/**
4343
* Gets the conversation component name.
4444
*
4545
* @return the conversation component name
4646
*/
47-
public String getLlmName() {
48-
return llmName;
47+
public String getName() {
48+
return name;
4949
}
5050

5151
/**
52-
* Gets the list of Dapr conversation inputs.
52+
* Gets the list of Dapr conversation input.
5353
*
54-
* @return the list of conversation inputs
54+
* @return the list of conversation input
5555
*/
56-
public List<ConversationInput> getConversationInputs() {
57-
return daprConversationInputs;
56+
public List<ConversationInput> getInputs() {
57+
return inputs;
5858
}
5959

6060
/**
@@ -116,4 +116,4 @@ public ConversationRequest setTemperature(double temperature) {
116116
this.temperature = temperature;
117117
return this;
118118
}
119-
}
119+
}

sdk/src/main/java/io/dapr/client/domain/ConversationResponse.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ public class ConversationResponse {
2323

2424
private String contextId;
2525

26-
private final List<ConversationOutput> daprConversationOutputs;
26+
private final List<ConversationOutput> outputs;
2727

2828
/**
2929
* Constructor.
3030
*
3131
* @param contextId context id supplied to LLM.
32-
* @param daprConversationOutputs outputs from the LLM.
32+
* @param outputs outputs from the LLM.
3333
*/
34-
public ConversationResponse(String contextId, List<ConversationOutput> daprConversationOutputs) {
34+
public ConversationResponse(String contextId, List<ConversationOutput> outputs) {
3535
this.contextId = contextId;
36-
this.daprConversationOutputs = daprConversationOutputs;
36+
this.outputs = outputs;
3737
}
3838

3939
/**
@@ -51,6 +51,6 @@ public String getContextId() {
5151
* @return List{@link ConversationOutput}.
5252
*/
5353
public List<ConversationOutput> getConversationOutpus() {
54-
return Collections.unmodifiableList(this.daprConversationOutputs);
54+
return Collections.unmodifiableList(this.outputs);
5555
}
5656
}

sdk/src/main/java/io/dapr/client/domain/ConversationRole.java

-35
This file was deleted.

0 commit comments

Comments
 (0)