Skip to content

Commit 075ca37

Browse files
committed
feat(app): support file_list
1 parent 794ed49 commit 075ca37

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

samples/ApplicationCalls.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,53 @@ public static void callWithThinking() throws NoApiKeyException, InputRequiredExc
318318
Application application = new Application();
319319
Flowable<ApplicationResult> result = application.streamCall(param);
320320
result.blockingForEach(data -> System.out.printf("result: %s%n", data));
321-
// result.blockingForEach(data -> System.out.printf(data.getOutput().getText()));
322321
System.out.print("\n");
323322
}
324323

324+
/**
325+
* Call with file list sample
326+
*
327+
* @throws NoApiKeyException Can not find api key
328+
* @throws ApiException The request failed, possibly
329+
* due to a network or data error.
330+
* @throws InputRequiredException Missing inputs.
331+
*/
332+
public static void callWithFileList()
333+
throws ApiException, NoApiKeyException, InputRequiredException {
334+
ApplicationParam param = ApplicationParam.builder()
335+
.appId(APP_ID)
336+
.prompt("总结文件内容")
337+
.files(Collections.singletonList(
338+
"https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"))
339+
.build();
340+
341+
Application application = new Application();
342+
ApplicationResult result = application.call(param);
343+
344+
System.out.println(JsonUtils.toJson(result));
345+
}
346+
347+
/**
348+
* Stream call with file list sample
349+
*
350+
* @throws NoApiKeyException Can not find api key
351+
* @throws InputRequiredException Missing inputs.
352+
*/
353+
public static void streamCallWithFileList()
354+
throws NoApiKeyException, InputRequiredException {
355+
ApplicationParam param = ApplicationParam.builder()
356+
.appId(APP_ID)
357+
.prompt("总结文件内容")
358+
.files(Collections.singletonList(
359+
"https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"))
360+
.incrementalOutput(true)
361+
.build();
362+
363+
Application application = new Application();
364+
Flowable<ApplicationResult> result = application.streamCall(param);
365+
result.blockingForEach(data -> System.out.println(JsonUtils.toJson(data)));
366+
}
367+
325368

326369
public static void main(String[] args) {
327370
try {
@@ -335,7 +378,9 @@ public static void main(String[] args) {
335378
// callWithAssistantServing();
336379
// ragCallWithDocReference();
337380
// callWithMoreParameters();
338-
callWithThinking();
381+
// callWithThinking();
382+
callWithFileList();
383+
// streamCallWithFileList();
339384
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
340385
System.out.printf("Exception: %s", e.getMessage());
341386
}

src/main/java/com/alibaba/dashscope/app/AppKeywords.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public interface AppKeywords {
3636

3737
String IMAGES = "image_list";
3838

39+
String FILE_LIST = "file_list";
40+
3941
String MCP_SERVERS = "mcp_servers";
4042

4143
String ENABLE_WEB_SEARCH = "enable_web_search";

src/main/java/com/alibaba/dashscope/app/ApplicationOutput.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public class ApplicationOutput {
3131
@SerializedName("session_id")
3232
private String sessionId;
3333

34+
/** Reject status indicates whether the response was rejected */
35+
@SerializedName("reject_status")
36+
private Boolean rejectStatus;
37+
3438
/** Thoughts of model planning for app */
3539
@SerializedName("thoughts")
3640
private List<Thought> thoughts;

src/main/java/com/alibaba/dashscope/app/ApplicationParam.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public class ApplicationParam extends HalfDuplexParamBase {
101101
/** image list */
102102
private List<String> images;
103103

104+
/** file list */
105+
private List<String> files;
106+
104107
/** rag options */
105108
private RagOptions ragOptions;
106109

@@ -267,6 +270,11 @@ public JsonObject getInput() {
267270
input.add(AppKeywords.IMAGES, imagesJson);
268271
}
269272

273+
if (files != null && !files.isEmpty()) {
274+
JsonArray fileListJson = JsonUtils.toJsonElement(files).getAsJsonArray();
275+
input.add(AppKeywords.FILE_LIST, fileListJson);
276+
}
277+
270278
return input;
271279
}
272280

0 commit comments

Comments
 (0)