-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: new api deleteLastConversation/request
Signed-off-by: Daniel Hu <[email protected]>
- Loading branch information
1 parent
8bf9648
commit 6a0fb9f
Showing
5 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/ai/devchat/devchat/handler/DeleteLastConversationRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters