Skip to content

Commit

Permalink
Feat: new api deleteLastConversation/request
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Hu <[email protected]>
  • Loading branch information
daniel-hutao committed Nov 23, 2023
1 parent 8bf9648 commit 6a0fb9f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
33 changes: 33 additions & 0 deletions api/topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,36 @@
}
}
```

## Delete Last Conversation in One Topic

### JS to Java

```json
{
"action": "deleteLastConversation/request",
"metadata": {
"callback": "responseFunctionName"
},
"payload": {
"promptHash": "xxx"
}
}
```

### Java to JS

- success

```json
{
"action": "deleteLastConversation/response",
"metadata": {
"status": "success",
"error": ""
},
"payload": {
"promptHash": "xxx"
}
}
```
1 change: 1 addition & 0 deletions src/main/java/ai/devchat/devchat/ActionHandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ActionHandlerFactory {
put(DevChatActions.GET_SETTING_REQUEST, GetSettingRequestHandler.class);
put(DevChatActions.UPDATE_SETTING_REQUEST, UpdateSettingRequestHandler.class);
put(DevChatActions.SHOW_SETTING_DIALOG_REQUEST, ShowSettingDialogRequestHandler.class);
put(DevChatActions.DELETE_LAST_CONVERSATION_REQUEST, DeleteLastConversationRequestHandler.class);
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ai/devchat/devchat/DevChatActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public class DevChatActions {
public static final String UPDATE_SETTING_REQUEST = "updateSetting/request";
public static final String UPDATE_SETTING_RESPONSE = "updateSetting/response";
public static final String SHOW_SETTING_DIALOG_REQUEST = "showSettingDialog/request";
public static final String DELETE_LAST_CONVERSATION_REQUEST = "deleteLastConversation/request";
public static final String DELETE_LAST_CONVERSATION_RESPONSE = "deleteLastConversation/response";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ai.devchat.devchat.handler;

import ai.devchat.cli.DevChatWrapper;
import ai.devchat.common.DevChatPathUtil;
import ai.devchat.common.Log;
import ai.devchat.devchat.ActionHandler;
import ai.devchat.devchat.DevChatActionHandler;
import ai.devchat.devchat.DevChatActions;
import com.alibaba.fastjson.JSONObject;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DeleteLastConversationRequestHandler implements ActionHandler {
private JSONObject metadata;
private JSONObject payload;
private final DevChatActionHandler devChatActionHandler;

public DeleteLastConversationRequestHandler(DevChatActionHandler devChatActionHandler) {
this.devChatActionHandler = devChatActionHandler;
}

@Override
public void executeAction() {
Log.info("Handling delete last conversation request");
String callbackFunc = metadata.getString("callback");
String promptHash = payload.getString("promptHash");

Map<String, List<String>> flags = new HashMap<>();
flags.put("delete", Collections.singletonList(promptHash));

String devchatCommandPath = DevChatPathUtil.getDevchatBinPath();
DevChatWrapper devchatWrapper = new DevChatWrapper(devchatCommandPath);

try {
devchatWrapper.runLogCommand(flags);

devChatActionHandler.sendResponse(DevChatActions.DELETE_LAST_CONVERSATION_RESPONSE, callbackFunc, (metadata, payload) -> {
metadata.put("status", "success");
metadata.put("error", "");
payload.put("promptHash", promptHash);
});
} catch (Exception e) {
devChatActionHandler.sendResponse(DevChatActions.DELETE_LAST_CONVERSATION_RESPONSE, callbackFunc, (metadata, payload) -> {
metadata.put("status", "error");
metadata.put("error", e.getMessage());
payload.put("promptHash", promptHash);
});
}
}

@Override
public void setMetadata(JSONObject metadata) {
this.metadata = metadata;
}

@Override
public void setPayload(JSONObject payload) {
this.payload = payload;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public ListModelsRequestHandler(DevChatActionHandler devChatActionHandler) {
this.devChatActionHandler = devChatActionHandler;
}


@Override
public void executeAction() {
Log.info("Handling list model request");
Expand Down

0 comments on commit 6a0fb9f

Please sign in to comment.