Skip to content

Commit 7af3a87

Browse files
cicoylesiri-varmaartur-ciocanuArtur Ciocanudependabot[bot]
authored
Add Tool Calling to Java SDK (#1481) (#1556)
* Use Java Bean for connection details and add more tests (#1317) * Use Java Bean for connection details and add more tests * Simplify mock setup * Adding even more tests for test coverage --------- * Update CONTRIBUTING.md * Bump codecov/codecov-action from 5.4.0 to 5.4.2 (#1318) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.0 to 5.4.2. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v5.4.0...v5.4.2) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... * Fix URL building logic (#1320) * Fix URL building logic * Add test for query params * Fix the assertion in the test * Adjust the tests * Remove uneeded changes from IT test * Revert some unintended changes * Simplify the testing a little bit * Adjust the test to use ServerRequest * Test removing things from method invoke controller * Add query param encoding test * Revert some unintended changes * Some tiny styles --------- * Generate updated javadocs for 1.14.1 * Add Conversation AI to Java SDK (#1235) * Conversation first commit * Add unit tests * change ai to conv * Move to single module * Remove module * Add Integration tests * Update sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprConversationIT.java * Fix things * Address comments * Import tag * Address comments * Make common config * Address comments * fix constant * fix constant * fix constant * fix s * Fix things * Fix things * Fix things * Make common config * Update README.md * Update README.md --------- * Add docs for usage of Jobs SDK (#1323) * Add doc for jobs * Add docs for Jobs * Apply suggestions from code review --------- * Use dapr/durabletask-java (#1336) * microsoft durabletask-java -> dapr durabletask-java * update another ref * 1.5.2 release * fix import order * Sdk new changes * Refine workflows * add ; * rm try --------- * Update master version to 1.16.0-SNAPSHOT * Renaming and exposing connection details (#1341) * [Master] Fix Vulnerabilities (#1354) * update okio * rm unused dep --------- * Feat Add TLS & mTLS support for gRPC with root CA and insecure mode (#1361) * feat: Support for GRPC ssl * add tests * fix CI * add back else if * channel cleanup * add root ca support * checkstyles * add insecure * fix checkstyles * use InsecureTrustManagerFactory * fix test --------- * Fix the issue with retries not happening correctly for Activities and Workflows (#1343) * Add coverage for some properties (#1297) * Make the DAPR version being used consistent across all tests (#1299) * Separate Dapr constants from IT container constants (#1315) * Use Java Bean for connection details and add more tests (#1317) * Use Java Bean for connection details and add more tests * Simplify mock setup * Adding even more tests for test coverage --------- * Update CONTRIBUTING.md * Bump codecov/codecov-action from 5.4.0 to 5.4.2 (#1318) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.0 to 5.4.2. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v5.4.0...v5.4.2) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... * Fix URL building logic (#1320) * Fix URL building logic * Add test for query params * Fix the assertion in the test * Adjust the tests * Remove uneeded changes from IT test * Revert some unintended changes * Simplify the testing a little bit * Adjust the test to use ServerRequest * Test removing things from method invoke controller * Add query param encoding test * Revert some unintended changes * Some tiny styles --------- * Generate updated javadocs for 1.14.1 * Add Conversation AI to Java SDK (#1235) * Conversation first commit * Add unit tests * change ai to conv * Move to single module * Remove module * Add Integration tests * Update sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprConversationIT.java * Fix things * Address comments * Import tag * Address comments * Make common config * Address comments * fix constant * fix constant * fix constant * fix s * Fix things * Fix things * Fix things * Make common config * Update README.md * Update README.md --------- * Add docs for usage of Jobs SDK (#1323) * Add doc for jobs * Add docs for Jobs * Apply suggestions from code review --------- * Use dapr/durabletask-java (#1336) * microsoft durabletask-java -> dapr durabletask-java * update another ref * 1.5.2 release * fix import order * Sdk new changes * Refine workflows * add ; * rm try --------- * Update master version to 1.16.0-SNAPSHOT * Fix NPE * Fix NPE * Fix NPE * Fix NPE * Fix NPE * Fix NPE * Fix things * Renaming and exposing connection details (#1341) * [Master] Fix Vulnerabilities (#1354) * update okio * rm unused dep --------- * Feat Add TLS & mTLS support for gRPC with root CA and insecure mode (#1361) * feat: Support for GRPC ssl * add tests * fix CI * add back else if * channel cleanup * add root ca support * checkstyles * add insecure * fix checkstyles * use InsecureTrustManagerFactory * fix test --------- * Address comments * Fix things * Fix things --------- * 1.5.4 (#1375) * Bump codecov/codecov-action from 5.4.2 to 5.4.3 (#1379) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.2 to 5.4.3. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v5.4.2...v5.4.3) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.4.3 dependency-type: direct:production update-type: version-update:semver-patch ... * Bump fossas/fossa-action from 1.6.0 to 1.7.0 (#1380) Bumps [fossas/fossa-action](https://github.com/fossas/fossa-action) from 1.6.0 to 1.7.0. - [Release notes](https://github.com/fossas/fossa-action/releases) - [Commits](fossas/fossa-action@v1.6.0...v1.7.0) --- updated-dependencies: - dependency-name: fossas/fossa-action dependency-version: 1.7.0 dependency-type: direct:production update-type: version-update:semver-minor ... * Fix component spec parsing (#1370) * Fix component spec parsing * Fix component spec parsing * Fix component spec metadata parsing * fix checkstyle-error --------- * chore: Add grpc keepalives (#1382) * chore: Add grpc keepalives * chore: Make grpc keepalive configurable * chore: Fix review comments * chore: Missing keepalive config for GRPC TLS INSECURE * chore: Add test * fix: Comment typo --------- * Fix : Typo in code comments (#1381) * Fix Typo in Comments * Update review comments --------- * Spring boot workflow patterns examples with mechanical markdown and tests (#1377) * Feat Add TLS & mTLS support for gRPC with root CA and insecure mode (#1361) * feat: Support for GRPC ssl * add tests * fix CI * add back else if * channel cleanup * add root ca support * checkstyles * add insecure * fix checkstyles * use InsecureTrustManagerFactory * fix test --------- * spring boot workflow patterns initial version * adding README for workflows * adding child example * updating examples to work with markdown tests * running mechanical markdown for workflow examples * Fix the issue with retries not happening correctly for Activities and Workflows (#1343) * Add coverage for some properties (#1297) * Make the DAPR version being used consistent across all tests (#1299) * Separate Dapr constants from IT container constants (#1315) * Use Java Bean for connection details and add more tests (#1317) * Use Java Bean for connection details and add more tests * Simplify mock setup * Adding even more tests for test coverage --------- * Update CONTRIBUTING.md * Bump codecov/codecov-action from 5.4.0 to 5.4.2 (#1318) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.0 to 5.4.2. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v5.4.0...v5.4.2) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... * Fix URL building logic (#1320) * Fix URL building logic * Add test for query params * Fix the assertion in the test * Adjust the tests * Remove uneeded changes from IT test * Revert some unintended changes * Simplify the testing a little bit * Adjust the test to use ServerRequest * Test removing things from method invoke controller * Add query param encoding test * Revert some unintended changes * Some tiny styles --------- * Generate updated javadocs for 1.14.1 * Add Conversation AI to Java SDK (#1235) * Conversation first commit * Add unit tests * change ai to conv * Move to single module * Remove module * Add Integration tests * Update sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprConversationIT.java * Fix things * Address comments * Import tag * Address comments * Make common config * Address comments * fix constant * fix constant * fix constant * fix s * Fix things * Fix things * Fix things * Make common config * Update README.md * Update README.md --------- * Add docs for usage of Jobs SDK (#1323) * Add doc for jobs * Add docs for Jobs * Apply suggestions from code review --------- * Use dapr/durabletask-java (#1336) * microsoft durabletask-java -> dapr durabletask-java * update another ref * 1.5.2 release * fix import order * Sdk new changes * Refine workflows * add ; * rm try --------- * Update master version to 1.16.0-SNAPSHOT * Fix NPE * Fix NPE * Fix NPE * Fix NPE * Fix NPE * Fix NPE * Fix things * Renaming and exposing connection details (#1341) * [Master] Fix Vulnerabilities (#1354) * update okio * rm unused dep --------- * Feat Add TLS & mTLS support for gRPC with root CA and insecure mode (#1361) * feat: Support for GRPC ssl * add tests * fix CI * add back else if * channel cleanup * add root ca support * checkstyles * add insecure * fix checkstyles * use InsecureTrustManagerFactory * fix test --------- * Address comments * Fix things * Fix things --------- * 1.5.4 (#1375) * fixing order Id correlation * fixing waiting time for tests to run * fixing app name * adding app name and removing log lines * Bump codecov/codecov-action from 5.4.2 to 5.4.3 (#1379) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.2 to 5.4.3. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v5.4.2...v5.4.3) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.4.3 dependency-type: direct:production update-type: version-update:semver-patch ... * Bump fossas/fossa-action from 1.6.0 to 1.7.0 (#1380) Bumps [fossas/fossa-action](https://github.com/fossas/fossa-action) from 1.6.0 to 1.7.0. - [Release notes](https://github.com/fossas/fossa-action/releases) - [Commits](fossas/fossa-action@v1.6.0...v1.7.0) --- updated-dependencies: - dependency-name: fossas/fossa-action dependency-version: 1.7.0 dependency-type: direct:production update-type: version-update:semver-minor ... * Fix component spec parsing (#1370) * Fix component spec parsing * Fix component spec parsing * Fix component spec metadata parsing * fix checkstyle-error --------- * Update spring-boot-examples/workflows/README.md * fixing comments * Update body.json * Update FanOutInWorkflow.java * clean up logs for multiple executions, for standalone mode * Update application.properties --------- * System Properties + Env Var Docs (#1384) * add properties file to docs and align system properties to env var name convention with . as _ * reset env var to what it was --------- * Updating docs to have spring boot 3.x banner and not hardcoded deps (#1366) * updating docs to have spring boot 3.x banner and not hardcoded deps * Update _index.md * Update _index.md Adding links to discord and github issues --------- * Cleaup Test Dependencies (#1332) * Update CONTRIBUTING.md * Fix things * Fix things? * Fix logback version * Fix logback version * Add pom * Add pom * Add properties * Added test scope * MArk as test * Update pom.xml * Update pom.xml --------- * chore: New task execution task id test (#1352) * chore: New task execution task id test test how taskExecutionTaskId can be used for idempotency * chore: Clean up not used files * docs: Task execution keys * test: Modify unit tests * Remove new lines --------- * Revert "chore: New task execution task id test (#1352)" (#1389) This reverts commit 949584f. * 1.5.5 (#1390) * Add Documentation for Conversation AI SDK (#1387) * Cleanup Spring Dependencies (#1334) * Update CONTRIBUTING.md * Fix spring * Add context * Phase 1 * Fix things * Fix things * Fix spring * Add context * Phase 1 * Fix things * Fix things * move version * Fix pom * change version * remove unused * Address comments * Fix test * Fix test * Fix things --------- * Bump org.springframework:spring-context in /dapr-spring (#1394) Bumps [org.springframework:spring-context](https://github.com/spring-projects/spring-framework) from 6.1.8 to 6.1.14. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](spring-projects/spring-framework@v6.1.8...v6.1.14) --- updated-dependencies: - dependency-name: org.springframework:spring-context dependency-version: 6.1.14 dependency-type: direct:production ... * Compensation example for Workflows (#1333) * add basic compensation example for wf * update commands to run + wf id * update readme + add mechanical markdown * fix import * fix mechanical markdown + add how to test it locally * move compensation example readme to workflows readme * Update BookCarActivity.java * Update BookFlightActivity.java * Update BookHotelActivity.java * Update BookTripClient.java * Update BookTripWorker.java * Update BookTripWorkflow.java * Update CancelCarActivity.java * Update CancelFlightActivity.java * Update CancelHotelActivity.java * add retry IT tests and catch TaskFailedException * add test for no compensation if successful and assert attempts * update mechanical markdown * add back pubsub... but this should be removed long term * try adding waitforsidecar * rm tests from examples pr * reset unintended changes --------- * Adding remote endpoint request from inside activity with retry (#1388) * adding remote endpoint request from inside activity with retry * adding retry with Microcks payloads * fixing review comments * chore: New task execution task id test (#1352) * chore: New task execution task id test test how taskExecutionTaskId can be used for idempotency * chore: Clean up not used files * docs: Task execution keys * test: Modify unit tests * Remove new lines --------- * Revert "chore: New task execution task id test (#1352)" (#1389) This reverts commit 949584f. * 1.5.5 (#1390) * Add Documentation for Conversation AI SDK (#1387) * Cleanup Spring Dependencies (#1334) * Update CONTRIBUTING.md * Fix spring * Add context * Phase 1 * Fix things * Fix things * Fix spring * Add context * Phase 1 * Fix things * Fix things * move version * Fix pom * change version * remove unused * Address comments * Fix test * Fix test * Fix things --------- * network is needed --------- * Bump org.springframework:spring-context in /dapr-spring (#1398) Bumps [org.springframework:spring-context](https://github.com/spring-projects/spring-framework) from 6.1.14 to 6.1.20. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](spring-projects/spring-framework@v6.1.14...v6.1.20) --- updated-dependencies: - dependency-name: org.springframework:spring-context dependency-version: 6.1.20 dependency-type: direct:production ... * Grouping IT tests per API surface (#1401) * Grouping IT tests per API surface * Fix build --------- * Ensure OTEL version from examples aligns with SDK and ITs (#1403) * chore: Support configuration for max grpc inbound message (#1411) * Adding Support for Suspend / Resume Workflows (#1405) * adding IT test * adding initial version of suspend/resume example * updating README * Update README.md * following Javi's suggestion * fixing wrong year in headers * fixing paths in one more README.md file * adding output validation * adding missing port * fixing check conditions --------- * Add retry handler support (#1412) * Add retry handler support * Wrap DurableTask objects * Rename method * Add isNonRetriable field to WorkflowTaskFailureDetails * Add unit test * Removed duplicate WorkflowFailureDetails class * Removed unneeded when statements in retry policy unit test * Add unit test to test both RetryPolicy and RetryHandler * Create toRetryPolicy method --------- * Pull out createTimer logic (#1419) * pull out logical changes from @salaboy's PR to release it * add missing import --------- * Make sure there no multiple empty lines and every file ends with a new line (#1417) * Automated Header Checks (#1416) * Bump org.springframework:spring-web in /dapr-spring (#1424) Bumps [org.springframework:spring-web](https://github.com/spring-projects/spring-framework) from 6.1.20 to 6.1.21. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](spring-projects/spring-framework@v6.1.20...v6.1.21) --- updated-dependencies: - dependency-name: org.springframework:spring-web dependency-version: 6.1.21 dependency-type: direct:production ... * Aligning Spring Boot and SpringFramework versions (#1427) * aligning versions * letting SB to manage the logback version, so it is aligned * removing dep from sdk-tests * removing logback --------- * Update pom.xml to have testcontainers 1.21.3 (#1436) * Adding examples to Spring Boot (duration, zoneddatetime and suspend/resume) (#1413) * implementing createtime with zoneddatetime * adding duration and zoneddatetime examples * using external event wf to test suspend resume --------- * Bump org.apache.commons:commons-lang3 from 3.9 to 3.18.0 (#1446) Bumps org.apache.commons:commons-lang3 from 3.9 to 3.18.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-lang3 dependency-version: 3.18.0 dependency-type: direct:development ... * Update dapr docs for Hugo upgrade (#1443) * Adds note about workflow start time (#1444) * Migrate PubSub removing flaky test (#1407) * Migrate PubSub removing flaky test * Adjust assertion * Change assert * Apply pull request suggestions * Use custom ObjectSerializer --------- * supporting spring boot property for API TOKEN on workflow interceptor (#1452) * Supporting placement and scheduler custom images (#1450) * supporting placement and scheduler custom images * Bump org.apache.commons:commons-lang3 from 3.9 to 3.18.0 (#1446) Bumps org.apache.commons:commons-lang3 from 3.9 to 3.18.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-lang3 dependency-version: 3.18.0 dependency-type: direct:development ... * Update dapr docs for Hugo upgrade (#1443) * Adds note about workflow start time (#1444) * adding test to validate canonical names with substitutes * Migrate PubSub removing flaky test (#1407) * Migrate PubSub removing flaky test * Adjust assertion * Change assert * Apply pull request suggestions * Use custom ObjectSerializer --------- * adding tests for coverage --------- * chore: Replace ossrh url (#1454) * Upgrading to 1.15.7 (#1458) * upgrading to 1.15.7 * using DAPR VERSION --------- * updating sched api on DaprContainer (#1462) * Adding app health check parameters (#1465) * adding app health check parameters * fixing style * testing with configure for coverage * updating sched api on DaprContainer (#1462) * fix Artur comments --------- * Add note about the dapr.client.* properties (#1467) * conversation ai * Fix pom * Fix pom * fix things * Fix things * docs: Add gRPC response settings to properties documentation (#1482) * docs: Add gRPC response settings to properties documentation * Apply suggestion from @javier-aliaga --------- * Generate updated javadocs for 1.14.2 * chore: Use 1.16.0 rc 2 (#1463) * chore: Use 1.16.0 rc * chore: Use dapr:1.16-rc.2 * chore: Add overwrite flag to jobs --------- * Add Failure Policy for Jobs SDK (#1448) * Update CONTRIBUTING.md * Ad… Signed-off-by: Artur Ciocanu <[email protected]> Signed-off-by: sirivarma <[email protected]> Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Dapr Bot <[email protected]> Signed-off-by: Siri Varma Vegiraju <[email protected]> Signed-off-by: siri-varma <[email protected]> Signed-off-by: Cassandra Coyle <[email protected]> Signed-off-by: Javier Aliaga <[email protected]> Signed-off-by: Deepak <[email protected]> Signed-off-by: salaboy <[email protected]> Signed-off-by: artur-ciocanu <[email protected]> Signed-off-by: Mason <[email protected]> Signed-off-by: Marc Duiker <[email protected]> Signed-off-by: joshvanl <[email protected]> Signed-off-by: Matheus Cruz <[email protected]> Signed-off-by: MyMirelHub <[email protected]> Signed-off-by: Mirel Isaj <[email protected]> Co-authored-by: Siri Varma Vegiraju <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Co-authored-by: Artur Ciocanu <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Dapr Bot <[email protected]> Co-authored-by: Dapr Bot <[email protected]> Co-authored-by: Javier Aliaga <[email protected]> Co-authored-by: Matheus Cruz <[email protected]> Co-authored-by: iddeepak <[email protected]> Co-authored-by: salaboy <[email protected]> Co-authored-by: Mason <[email protected]> Co-authored-by: Marc Duiker <[email protected]> Co-authored-by: Josh van Leeuwen <[email protected]> Co-authored-by: Mirel Isaj <[email protected]>
1 parent fd49754 commit 7af3a87

30 files changed

+3212
-59
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright 2021 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.conversation;
15+
16+
import io.dapr.client.DaprClientBuilder;
17+
import io.dapr.client.DaprPreviewClient;
18+
import io.dapr.client.domain.AssistantMessage;
19+
import io.dapr.client.domain.ConversationInputAlpha2;
20+
import io.dapr.client.domain.ConversationMessage;
21+
import io.dapr.client.domain.ConversationMessageContent;
22+
import io.dapr.client.domain.ConversationRequestAlpha2;
23+
import io.dapr.client.domain.ConversationResponseAlpha2;
24+
import io.dapr.client.domain.ConversationResultAlpha2;
25+
import io.dapr.client.domain.ConversationResultChoices;
26+
import io.dapr.client.domain.ConversationToolCalls;
27+
import io.dapr.client.domain.ConversationToolCallsOfFunction;
28+
import io.dapr.client.domain.SystemMessage;
29+
import io.dapr.client.domain.ToolMessage;
30+
import io.dapr.client.domain.UserMessage;
31+
import reactor.core.publisher.Mono;
32+
33+
import java.util.ArrayList;
34+
import java.util.List;
35+
36+
public class AssistantMessageDemo {
37+
/**
38+
* The main method to demonstrate conversation AI with assistant messages and conversation history.
39+
*
40+
* @param args Input arguments (unused).
41+
*/
42+
public static void main(String[] args) {
43+
try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) {
44+
System.out.println("Demonstrating Conversation AI with Assistant Messages and Conversation History");
45+
46+
// Create a conversation history with multiple message types
47+
List<ConversationMessage> conversationHistory = new ArrayList<>();
48+
49+
// 1. System message to set context
50+
SystemMessage systemMessage = new SystemMessage(List.of(
51+
new ConversationMessageContent("You are a helpful assistant that can help with weather queries.")
52+
));
53+
systemMessage.setName("WeatherBot");
54+
conversationHistory.add(systemMessage);
55+
56+
// 2. Initial user greeting
57+
UserMessage greeting = new UserMessage(List.of(
58+
new ConversationMessageContent("Hello! I need help with weather information.")
59+
));
60+
greeting.setName("User123");
61+
conversationHistory.add(greeting);
62+
63+
// 3. Assistant response with tool call
64+
AssistantMessage assistantResponse = new AssistantMessage(
65+
List.of(new ConversationMessageContent("I'll help you with weather information. Let me check the weather for you.")),
66+
List.of(new ConversationToolCalls(
67+
new ConversationToolCallsOfFunction("get_weather", "{\"location\": \"San Francisco\", \"unit\": \"fahrenheit\"}")
68+
))
69+
);
70+
assistantResponse.setName("WeatherBot");
71+
conversationHistory.add(assistantResponse);
72+
73+
// 4. Tool response (simulating weather API response)
74+
ToolMessage toolResponse = new ToolMessage(List.of(
75+
new ConversationMessageContent("{\"temperature\": \"72F\", \"condition\": \"sunny\", \"humidity\": \"65%\"}")
76+
));
77+
toolResponse.setName("weather_api");
78+
conversationHistory.add(toolResponse);
79+
80+
// 5. Current user question
81+
UserMessage currentQuestion = new UserMessage(List.of(
82+
new ConversationMessageContent("Based on that weather data, should I wear a jacket today?")
83+
));
84+
currentQuestion.setName("User123");
85+
conversationHistory.add(currentQuestion);
86+
87+
// Create conversation input with the full history
88+
ConversationInputAlpha2 conversationInput = new ConversationInputAlpha2(conversationHistory);
89+
conversationInput.setScrubPii(false);
90+
91+
// Create the conversation request
92+
ConversationRequestAlpha2 request = new ConversationRequestAlpha2("echo", List.of(conversationInput))
93+
.setContextId("assistant-demo-context")
94+
.setTemperature(0.8d);
95+
96+
// Send the request
97+
System.out.println("Sending conversation with assistant messages and history...");
98+
System.out.println("Conversation includes:");
99+
System.out.println("- System message (context setting)");
100+
System.out.println("- User greeting");
101+
System.out.println("- Assistant response with tool call");
102+
System.out.println("- Tool response with weather data");
103+
System.out.println("- User follow-up question");
104+
105+
Mono<ConversationResponseAlpha2> responseMono = client.converseAlpha2(request);
106+
ConversationResponseAlpha2 response = responseMono.block();
107+
108+
// Process and display the response
109+
if (response != null && response.getOutputs() != null && !response.getOutputs().isEmpty()) {
110+
ConversationResultAlpha2 result = response.getOutputs().get(0);
111+
if (result.getChoices() != null && !result.getChoices().isEmpty()) {
112+
ConversationResultChoices choice = result.getChoices().get(0);
113+
114+
if (choice.getMessage() != null && choice.getMessage().getContent() != null) {
115+
System.out.printf("Assistant Response: %s%n", choice.getMessage().getContent());
116+
}
117+
118+
// Check for additional tool calls in the response
119+
if (choice.getMessage() != null && choice.getMessage().getToolCalls() != null) {
120+
System.out.println("Assistant requested additional tool calls:");
121+
choice.getMessage().getToolCalls().forEach(toolCall -> {
122+
System.out.printf("Tool: %s, Arguments: %s%n",
123+
toolCall.getFunction().getName(),
124+
toolCall.getFunction().getArguments());
125+
});
126+
}
127+
}
128+
}
129+
130+
System.out.println("Assistant message demonstration completed.");
131+
132+
} catch (Exception e) {
133+
throw new RuntimeException(e);
134+
}
135+
}
136+
}

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,51 @@ Run `dapr init` to initialize Dapr in Self-Hosted Mode if it's not already initi
4545
### Running the example
4646

4747
This example uses the Java SDK Dapr client in order to **Converse** with an LLM.
48-
`DemoConversationAI.java` is the example class demonstrating these features.
48+
`UserMessageDemo.java` is the example class demonstrating these features.
4949
Kindly check [DaprPreviewClient.java](https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/DaprPreviewClient.java) for a detailed description of the supported APIs.
5050

5151
```java
52-
public class DemoConversationAI {
52+
public class UserMessageDemo {
5353
/**
5454
* The main method to start the client.
5555
*
5656
* @param args Input arguments (unused).
5757
*/
5858
public static void main(String[] args) {
59-
try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) {
59+
Map<Property<?>, String> overrides = Map.of(
60+
Properties.HTTP_PORT, "3500",
61+
Properties.GRPC_PORT, "50001"
62+
);
63+
64+
try (DaprPreviewClient client = new DaprClientBuilder().withPropertyOverrides(overrides).buildPreviewClient()) {
6065
System.out.println("Sending the following input to LLM: Hello How are you? This is the my number 672-123-4567");
6166

62-
ConversationInput daprConversationInput = new ConversationInput("Hello How are you? "
63-
+ "This is the my number 672-123-4567");
67+
// Create user message with content
68+
UserMessage userMessage = new UserMessage(List.of(new ConversationMessageContent("Hello How are you? "
69+
+ "This is the my number 672-123-4567")));
70+
71+
// Create conversation input with the user message
72+
ConversationInputAlpha2 daprConversationInput = new ConversationInputAlpha2(List.of(userMessage));
6473

6574
// Component name is the name provided in the metadata block of the conversation.yaml file.
66-
Mono<ConversationResponse> responseMono = client.converse(new ConversationRequest("echo",
75+
Mono<ConversationResponseAlpha2> responseMono = client.converseAlpha2(new ConversationRequestAlpha2("echo",
6776
List.of(daprConversationInput))
6877
.setContextId("contextId")
69-
.setScrubPii(true).setTemperature(1.1d));
70-
ConversationResponse response = responseMono.block();
71-
System.out.printf("Conversation output: %s", response.getConversationOutpus().get(0).getResult());
78+
.setScrubPii(true)
79+
.setTemperature(1.1d));
80+
81+
ConversationResponseAlpha2 response = responseMono.block();
82+
83+
// Extract and print the conversation result
84+
if (response != null && response.getOutputs() != null && !response.getOutputs().isEmpty()) {
85+
ConversationResultAlpha2 result = response.getOutputs().get(0);
86+
if (result.getChoices() != null && !result.getChoices().isEmpty()) {
87+
ConversationResultChoices choice = result.getChoices().get(0);
88+
if (choice.getMessage() != null && choice.getMessage().getContent() != null) {
89+
System.out.printf("Conversation output: %s", choice.getMessage().getContent());
90+
}
91+
}
92+
}
7293
} catch (Exception e) {
7394
throw new RuntimeException(e);
7495
}
@@ -88,7 +109,7 @@ sleep: 10
88109
-->
89110

90111
```bash
91-
dapr run --resources-path ./components/conversation --app-id myapp --app-port 8080 --dapr-http-port 3500 --dapr-grpc-port 51439 --log-level debug -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.conversation.DemoConversationAI
112+
dapr run --resources-path ./components/conversation --app-id myapp --app-port 8080 --dapr-http-port 3500 --dapr-grpc-port 51439 --log-level debug -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.conversation.UserMessageDemo
92113
```
93114

94115
<!-- END_STEP -->
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2021 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.conversation;
15+
16+
import io.dapr.client.DaprClientBuilder;
17+
import io.dapr.client.DaprPreviewClient;
18+
import io.dapr.client.domain.ConversationInputAlpha2;
19+
import io.dapr.client.domain.ConversationMessageContent;
20+
import io.dapr.client.domain.ConversationRequestAlpha2;
21+
import io.dapr.client.domain.ConversationResponseAlpha2;
22+
import io.dapr.client.domain.ConversationResultAlpha2;
23+
import io.dapr.client.domain.ConversationResultChoices;
24+
import io.dapr.client.domain.ConversationTools;
25+
import io.dapr.client.domain.ConversationToolsFunction;
26+
import io.dapr.client.domain.SystemMessage;
27+
import io.dapr.client.domain.UserMessage;
28+
import reactor.core.publisher.Mono;
29+
30+
import java.util.HashMap;
31+
import java.util.List;
32+
import java.util.Map;
33+
34+
public class ToolsCallDemo {
35+
/**
36+
* The main method to demonstrate conversation AI with tools/function calling.
37+
*
38+
* @param args Input arguments (unused).
39+
*/
40+
public static void main(String[] args) {
41+
try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) {
42+
System.out.println("Demonstrating Conversation AI with Tools/Function Calling");
43+
44+
// Create system message to set context
45+
SystemMessage systemMessage = new SystemMessage(List.of(
46+
new ConversationMessageContent("You are a helpful weather assistant. Use the provided tools to get weather information.")
47+
));
48+
49+
// Create user message asking for weather
50+
UserMessage userMessage = new UserMessage(List.of(
51+
new ConversationMessageContent("What's the weather like in San Francisco?")
52+
));
53+
54+
// Create conversation input with messages
55+
ConversationInputAlpha2 conversationInput = new ConversationInputAlpha2(List.of(systemMessage, userMessage));
56+
57+
// Define function parameters for the weather tool
58+
Map<String, Object> functionParams = new HashMap<>();
59+
functionParams.put("location", "string");
60+
functionParams.put("unit", "string");
61+
62+
// Create the weather function definition
63+
ConversationToolsFunction weatherFunction = new ConversationToolsFunction("get_current_weather", functionParams);
64+
weatherFunction.setDescription("Get the current weather for a specified location");
65+
66+
// Create the tool wrapper
67+
ConversationTools weatherTool = new ConversationTools(weatherFunction);
68+
69+
// Create the conversation request with tools
70+
ConversationRequestAlpha2 request = new ConversationRequestAlpha2("echo", List.of(conversationInput))
71+
.setContextId("weather-demo-context")
72+
.setTemperature(0.7d)
73+
.setTools(List.of(weatherTool));
74+
75+
// Send the request
76+
System.out.println("Sending request to AI with weather tool available...");
77+
Mono<ConversationResponseAlpha2> responseMono = client.converseAlpha2(request);
78+
ConversationResponseAlpha2 response = responseMono.block();
79+
80+
// Process and display the response
81+
if (response != null && response.getOutputs() != null && !response.getOutputs().isEmpty()) {
82+
ConversationResultAlpha2 result = response.getOutputs().get(0);
83+
if (result.getChoices() != null && !result.getChoices().isEmpty()) {
84+
ConversationResultChoices choice = result.getChoices().get(0);
85+
86+
// Check if the AI wants to call a tool
87+
if (choice.getMessage() != null && choice.getMessage().getToolCalls() != null) {
88+
System.out.println("AI requested to call tools:");
89+
choice.getMessage().getToolCalls().forEach(toolCall -> {
90+
System.out.printf("Tool: %s, Arguments: %s%n",
91+
toolCall.getFunction().getName(),
92+
toolCall.getFunction().getArguments());
93+
});
94+
}
95+
96+
// Display the message content if available
97+
if (choice.getMessage() != null && choice.getMessage().getContent() != null) {
98+
System.out.printf("AI Response: %s%n", choice.getMessage().getContent());
99+
}
100+
}
101+
}
102+
103+
System.out.println("Tools call demonstration completed.");
104+
105+
} catch (Exception e) {
106+
throw new RuntimeException(e);
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)