Skip to content

Commit 71d240e

Browse files
xiong-binbinxiongbinbin
andauthored
upgrade (#9)
1. Add messages for application call. 2. Add structuredFilter for rag options. --------- Co-authored-by: xiongbinbin <xiongbinbin.xbb@alibaba-inc.com>
1 parent f7b3241 commit 71d240e

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
package com.alibaba.dashscope.app;
33

44
import static com.alibaba.dashscope.utils.ApiKeywords.HISTORY;
5+
import static com.alibaba.dashscope.utils.ApiKeywords.MESSAGES;
56
import static com.alibaba.dashscope.utils.ApiKeywords.PROMPT;
67

78
import com.alibaba.dashscope.base.HalfDuplexParamBase;
89
import com.alibaba.dashscope.common.History;
10+
import com.alibaba.dashscope.common.Message;
11+
import com.alibaba.dashscope.common.Role;
912
import com.alibaba.dashscope.exception.InputRequiredException;
1013
import com.alibaba.dashscope.utils.ApiKeywords;
1114
import com.alibaba.dashscope.utils.JsonUtils;
@@ -42,6 +45,9 @@ public class ApplicationParam extends HalfDuplexParamBase {
4245
/** chat history */
4346
private List<History> history;
4447

48+
/** chat message */
49+
private List<Message> messages;
50+
4551
/** Session id for storing chat history note: this will be ignored if history passed */
4652
private String sessionId;
4753

@@ -164,13 +170,27 @@ public JsonObject getHttpBody() {
164170
public JsonObject getInput() {
165171
JsonObject input = new JsonObject();
166172

167-
input.addProperty(PROMPT, getPrompt());
168173
input.addProperty(AppKeywords.SESSION_ID, getSessionId());
169174
input.addProperty(AppKeywords.MEMORY_ID, memoryId);
170175

171-
if (history != null && !history.isEmpty()) {
172-
JsonArray historyJson = JsonUtils.toJsonElement(history).getAsJsonArray();
176+
if (getMessages() != null && !getMessages().isEmpty()) {
177+
JsonArray messagesJson = new JsonArray();
178+
messagesJson.addAll(JsonUtils.toJsonArray(getMessages()));
179+
if (getPrompt() != null) {
180+
Message msg = Message.builder().role(Role.USER.getValue()).content(getPrompt()).build();
181+
messagesJson.add(JsonUtils.toJsonElement(msg));
182+
}
183+
input.add(MESSAGES, messagesJson);
184+
} else if (getHistory() != null && !getHistory().isEmpty()) {
185+
JsonArray historyJson = JsonUtils.toJsonElement(getHistory()).getAsJsonArray();
173186
input.add(HISTORY, historyJson);
187+
if (getPrompt() != null) {
188+
input.addProperty(PROMPT, getPrompt());
189+
}
190+
} else {
191+
if (getPrompt() != null) {
192+
input.addProperty(PROMPT, getPrompt());
193+
}
174194
}
175195

176196
if (bizParams != null) {
@@ -197,8 +217,8 @@ public ByteBuffer getBinaryData() {
197217

198218
@Override
199219
public void validate() throws InputRequiredException {
200-
if (getPrompt() == null) {
201-
throw new InputRequiredException("prompt must not be null");
220+
if (getPrompt() == null && (getMessages() == null || getMessages().isEmpty())) {
221+
throw new InputRequiredException("prompt or messages must not be null");
202222
}
203223
}
204224
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ public class RagOptions {
4040
/** structured filter of knowledge base query */
4141
@SerializedName("structured_filter")
4242
private JsonObject structuredFilter;
43+
44+
/** file ID is a temporary file associated with the current session */
45+
@SerializedName("session_file_ids")
46+
private List<String> sessionFileIds;
4347
}

0 commit comments

Comments
 (0)