MCPcopy Create free account
hub / github.com/dashscope/dashscope-sdk-java / ApplicationCalls

Class ApplicationCalls

samples/ApplicationCalls.java:23–411  ·  view source on GitHub ↗

Title App Completion call samples. Description App Completion call samples. Created at 2024-02-26 09:50 @since jdk8

Source from the content-addressed store, hash-verified

21 */
22
23public class ApplicationCalls {
24 private static final String WORKSPACE;
25 private static final String APP_ID;
26
27 static {
28 WORKSPACE = System.getenv("WORKSPACE_ID");
29 APP_ID = System.getenv("APP_ID");
30 }
31
32 /**
33 * Rag application call sample
34 *
35 * @throws NoApiKeyException Can not find api key
36 * @throws ApiException The request failed, possibly due to a network or data error.
37 * @throws InputRequiredException Missing inputs.
38 */
39 public static void ragCall()
40 throws ApiException, NoApiKeyException, InputRequiredException {
41 ApplicationParam param = ApplicationParam.builder()
42 .appId(APP_ID)
43 .prompt("API接口说明中, TopP参数改如何传递?")
44 .topP(0.2)
45 .build();
46
47 Application application = new Application();
48 ApplicationResult result = application.call(param);
49
50 System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
51 result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
52
53 if (result.getUsage() != null && result.getUsage().getModels() != null) {
54 for (ApplicationUsage.ModelUsage usage : result.getUsage().getModels()) {
55 System.out.printf("modelId: %s, inputTokens: %d, outputTokens: %d\n",
56 usage.getModelId(), usage.getInputTokens(), usage.getOutputTokens());
57 }
58 }
59 }
60
61 /**
62 * Rag application call with tags sample
63 *
64 * @throws NoApiKeyException Can not find api key
65 * @throws ApiException The request failed, possibly due to a network or data error.
66 * @throws InputRequiredException Missing inputs.
67 */
68 public static void ragCallWithTags()
69 throws ApiException, NoApiKeyException, InputRequiredException {
70 ApplicationParam param = ApplicationParam.builder()
71 .appId(APP_ID)
72 .prompt("API接口说明中, TopP参数改如何传递?")
73 .topP(0.2)
74 // 开启检索过程信息返回结果
75 .hasThoughts(true)
76 .build();
77
78 Application application = new Application();
79 ApplicationResult result = application.call(param);
80

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected