Skip to content

Commit

Permalink
Feat: new api listModels/request is ready
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 14, 2023
1 parent 5f072c3 commit 3242772
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
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 @@ -19,6 +19,7 @@ public class ActionHandlerFactory {
put(DevChatActions.REPLACE_FILE_CONTENT_REQUEST, ReplaceFileContentHandler.class);
put(DevChatActions.VIEW_DIFF_REQUEST, ViewDiffRequestHandler.class);
put(DevChatActions.LIST_CONTEXTS_REQUEST, ListContextsRequestHandler.class);
put(DevChatActions.LIST_MODELS_REQUEST, ListModelsRequestHandler.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 @@ -21,4 +21,6 @@ public class DevChatActions {
public static final String VIEW_DIFF_RESPONSE = "viewDiff/response";
public static final String LIST_CONTEXTS_REQUEST = "listContexts/request";
public static final String LIST_CONTEXTS_RESPONSE = "listContexts/response";
public static final String LIST_MODELS_REQUEST = "listModels/request";
public static final String LIST_MODELS_RESPONSE = "listModels/response";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ai.devchat.devchat.handler;

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.ArrayList;
import java.util.List;

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

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


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

String callbackFunc = metadata.getString("callback");

List<String> modelList = new ArrayList<>();
modelList.add("gpt-3.5-turbo");
modelList.add("gpt-4");

devChatActionHandler.sendResponse(DevChatActions.LIST_CONTEXTS_RESPONSE, callbackFunc, (metadata, payload) -> {
metadata.put("status", "success");
metadata.put("error", "");

payload.put("models", modelList);
});
}

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

@Override
public void setPayload(JSONObject payload) {
this.payload = payload;
}
}

0 comments on commit 3242772

Please sign in to comment.