Skip to content

[app-builder] 处理表单无法重新对话的问题 #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import static modelengine.fit.jober.aipp.util.UsefulUtils.doIfNull;
import static modelengine.fitframework.util.ObjectUtils.cast;

import com.alibaba.fastjson.JSON;

import lombok.Getter;
import modelengine.fel.tool.service.ToolService;
import modelengine.fit.jade.aipp.model.dto.ModelAccessInfo;
Expand Down Expand Up @@ -80,6 +82,7 @@
import modelengine.fit.jober.aipp.dto.export.AppExportFlowGraph;
import modelengine.fit.jober.aipp.dto.template.TemplateAppCreateDto;
import modelengine.fit.jober.aipp.dto.template.TemplateInfoDto;
import modelengine.fit.jober.aipp.entity.AippInstLog;
import modelengine.fit.jober.aipp.entity.ChatSession;
import modelengine.fit.jober.aipp.enums.AippMetaStatusEnum;
import modelengine.fit.jober.aipp.enums.AippTypeEnum;
Expand Down Expand Up @@ -578,6 +581,10 @@ public void restart(AppTaskInstance instance, Map<String, Object> restartParams,
OperationContext context, Consumer<RunContext> onFinished) {
List<AppLog> instanceLogs = instance.getLogs();
List<QueryChatRsp> chatList = instance.getChats();
if (CollectionUtils.isEmpty(chatList)) {
LOGGER.error("ChatList is empty. [InstanceId={}]", instance.getId());
throw new AippParamException(AippErrCode.RE_CHAT_FAILED);
}

// 合并参数.
AppLog appLog = instanceLogs.iterator().next();
Expand All @@ -586,21 +593,37 @@ public void restart(AppTaskInstance instance, Map<String, Object> restartParams,

RunContext runContext = new RunContext(new HashMap<>(), context);
runContext.setRestartMode(cast(mergedRestartParams.getOrDefault(RESTART_MODE, OVERWRITE.getMode())));
runContext.setAppId(chatList.get(0).getAppId());
runContext.setChatId(chatList.get(0).getChatId());

QueryChatRsp mostRecentRsp = chatList.get(0);
runContext.setAppId(mostRecentRsp.getAppId());
runContext.setChatId(mostRecentRsp.getChatId());
runContext.setUserContext(mergedRestartParams);
runContext.putAllToBusiness(mergedRestartParams);
runContext.setQuestion(appLog.getLogData().getQuestion());
runContext.setQuestion(this.getQuestion(appLog.getLogData()));
if (chatList.size() == 2) {
runContext.setAtChatId(chatList.get(1).getChatId());
}
if (runContext.isOverWriteMode()) {
instance.overWrite();
}
this.run(runContext, session);
boolean isDebug =
StringUtils.equals(AppState.INACTIVE.getName(), this.getState(mostRecentRsp.getAttributes()));
if (isDebug) {
this.debug(runContext, session);
} else {
this.run(runContext, session);
}
onFinished.accept(runContext);
}

private String getState(String attributes) {
return ObjectUtils.cast(JsonUtils.parseObject(attributes).get(AippConst.ATTR_CHAT_STATE_KEY));
}

private String getQuestion(AippInstLog instLog) {
return JSON.parseObject(instLog.getLogData()).getString("msg");
}

/**
* 获取 icon.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,12 @@ public void testRestartNormally() {
AppTaskInstance instance = mock(AppTaskInstance.class);
when(AppVersionTest.this.appTaskInstanceService.getInstanceById(anyString(), any())).thenReturn(
Optional.of(instance));
when(instance.getChats()).thenReturn(
List.of(QueryChatRsp.builder().appId("app_version_1").chatId("chat_1").build()));
String attributes = "{\"state\":\"active\"}";
when(instance.getChats()).thenReturn(List.of(QueryChatRsp.builder()
.appId("app_version_1")
.attributes(attributes)
.chatId("chat_1")
.build()));

AppLog appLog = mock(AppLog.class);
when(instance.getLogs()).thenReturn(List.of(appLog));
Expand Down Expand Up @@ -716,8 +720,12 @@ public void testRestartWithAtChatId() {
AppTaskInstance instance = mock(AppTaskInstance.class);
when(AppVersionTest.this.appTaskInstanceService.getInstanceById(anyString(), any())).thenReturn(
Optional.of(instance));
when(instance.getChats()).thenReturn(
List.of(QueryChatRsp.builder().appId("app_version_1").chatId("chat_1").build(), atChat));
String attributes = "{\"state\":\"active\"}";
when(instance.getChats()).thenReturn(List.of(QueryChatRsp.builder()
.appId("app_version_1")
.chatId("chat_1")
.attributes(attributes)
.build(), atChat));

AppLog appLog = mock(AppLog.class);
when(instance.getLogs()).thenReturn(List.of(appLog));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package modelengine.fit.jober.aipp.entity;

import com.alibaba.fastjson.JSON;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -62,13 +60,4 @@ public class AippInstLog {

@Property(description = "历史数据类型 {@link AippInstLogType}")
private String logType;

/**
* 获取 question 数据.
*
* @return {@link String} 问题.
*/
public String getQuestion() {
return JSON.parseObject(this.getLogData()).getString("msg");
}
}