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