Skip to content

Commit a4625fe

Browse files
committed
Address comments
Signed-off-by: sirivarma <[email protected]>
1 parent 24a514f commit a4625fe

File tree

1 file changed

+42
-47
lines changed

1 file changed

+42
-47
lines changed

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

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,22 +1721,7 @@ public Mono<ConversationResponseAlpha2> converseAlpha2(ConversationRequestAlpha2
17211721
throw new IllegalArgumentException("Conversation Inputs cannot be null or empty.");
17221722
}
17231723

1724-
DaprProtos.ConversationRequestAlpha2.Builder builder = DaprProtos.ConversationRequestAlpha2
1725-
.newBuilder()
1726-
.setTemperature(conversationRequestAlpha2.getTemperature())
1727-
.setScrubPii(conversationRequestAlpha2.isScrubPii())
1728-
.setName(conversationRequestAlpha2.getName());
1729-
1730-
if (conversationRequestAlpha2.getContextId() != null) {
1731-
builder.setContextId(conversationRequestAlpha2.getContextId());
1732-
}
1733-
1734-
if (conversationRequestAlpha2.getToolChoice() != null) {
1735-
builder.setToolChoice(conversationRequestAlpha2.getToolChoice());
1736-
}
1737-
1738-
DaprProtos.ConversationRequestAlpha2 protoRequest = buildConversationRequestProto(conversationRequestAlpha2,
1739-
builder);
1724+
DaprProtos.ConversationRequestAlpha2 protoRequest = buildConversationRequestProto(conversationRequestAlpha2);
17401725

17411726
Mono<DaprProtos.ConversationResponseAlpha2> conversationResponseMono = Mono.deferContextual(
17421727
context -> this.createMono(
@@ -1754,17 +1739,32 @@ public Mono<ConversationResponseAlpha2> converseAlpha2(ConversationRequestAlpha2
17541739
}
17551740
}
17561741

1757-
private DaprProtos.ConversationRequestAlpha2 buildConversationRequestProto(ConversationRequestAlpha2 request,
1758-
DaprProtos.ConversationRequestAlpha2.Builder builder) {
1742+
private DaprProtos.ConversationRequestAlpha2 buildConversationRequestProto(ConversationRequestAlpha2 request) {
1743+
DaprProtos.ConversationRequestAlpha2.Builder builder = DaprProtos.ConversationRequestAlpha2
1744+
.newBuilder()
1745+
.setTemperature(request.getTemperature())
1746+
.setScrubPii(request.isScrubPii())
1747+
.setName(request.getName());
1748+
1749+
if (request.getContextId() != null) {
1750+
builder.setContextId(request.getContextId());
1751+
}
1752+
1753+
if (request.getToolChoice() != null) {
1754+
builder.setToolChoice(request.getToolChoice());
1755+
}
1756+
1757+
17591758
if (request.getTools() != null) {
1760-
buildConversationTools(request.getTools(), builder);
1759+
for (ConversationTools tool : request.getTools()) {
1760+
builder.addTools(buildConversationTools(tool));
1761+
}
17611762
}
17621763

17631764
if (request.getMetadata() != null) {
17641765
builder.putAllMetadata(request.getMetadata());
17651766
}
17661767

1767-
17681768
if (request.getParameters() != null) {
17691769
Map<String, Any> parameters = request.getParameters()
17701770
.entrySet().stream()
@@ -1800,39 +1800,34 @@ private DaprProtos.ConversationRequestAlpha2 buildConversationRequestProto(Conve
18001800
return builder.build();
18011801
}
18021802

1803-
private void buildConversationTools(List<ConversationTools> tools,
1804-
DaprProtos.ConversationRequestAlpha2.Builder builder) {
1805-
for (ConversationTools tool : tools) {
1806-
ConversationToolsFunction function = tool.getFunction();
1803+
private DaprProtos.ConversationTools buildConversationTools(ConversationTools tool) {
1804+
ConversationToolsFunction function = tool.getFunction();
18071805

1808-
DaprProtos.ConversationToolsFunction.Builder protoFunction = DaprProtos.ConversationToolsFunction.newBuilder()
1809-
.setName(function.getName());
1806+
DaprProtos.ConversationToolsFunction.Builder protoFunction = DaprProtos.ConversationToolsFunction.newBuilder()
1807+
.setName(function.getName());
18101808

1811-
if (function.getDescription() != null) {
1812-
protoFunction.setDescription(function.getDescription());
1813-
}
1809+
if (function.getDescription() != null) {
1810+
protoFunction.setDescription(function.getDescription());
1811+
}
18141812

1815-
if (function.getParameters() != null) {
1816-
Map<String, Value> functionParams = function.getParameters()
1817-
.entrySet().stream()
1818-
.collect(Collectors.toMap(
1819-
Map.Entry::getKey,
1820-
e -> {
1821-
try {
1822-
return ProtobufValueHelper.toProtobufValue(e.getValue());
1823-
} catch (IOException ex) {
1824-
throw new RuntimeException(ex);
1825-
}
1813+
if (function.getParameters() != null) {
1814+
Map<String, Value> functionParams = function.getParameters()
1815+
.entrySet().stream()
1816+
.collect(Collectors.toMap(
1817+
Map.Entry::getKey,
1818+
e -> {
1819+
try {
1820+
return ProtobufValueHelper.toProtobufValue(e.getValue());
1821+
} catch (IOException ex) {
1822+
throw new RuntimeException(ex);
18261823
}
1827-
));
1828-
1829-
protoFunction.setParameters(Struct.newBuilder().putAllFields(functionParams).build());
1830-
}
1824+
}
1825+
));
18311826

1832-
builder.addTools(DaprProtos.ConversationTools.newBuilder()
1833-
.setFunction(protoFunction)
1834-
.build());
1827+
protoFunction.setParameters(Struct.newBuilder().putAllFields(functionParams).build());
18351828
}
1829+
1830+
return DaprProtos.ConversationTools.newBuilder().setFunction(protoFunction).build();
18361831
}
18371832

18381833
private DaprProtos.ConversationMessage buildConversationMessage(ConversationMessage message) {

0 commit comments

Comments
 (0)