diff --git a/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java b/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java index db04fc2..bf49cbd 100644 --- a/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java +++ b/src/main/java/ai/devchat/devchat/ActionHandlerFactory.java @@ -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); } }; diff --git a/src/main/java/ai/devchat/devchat/DevChatActions.java b/src/main/java/ai/devchat/devchat/DevChatActions.java index 07db38e..6f596ca 100644 --- a/src/main/java/ai/devchat/devchat/DevChatActions.java +++ b/src/main/java/ai/devchat/devchat/DevChatActions.java @@ -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"; } diff --git a/src/main/java/ai/devchat/devchat/handler/ListModelsRequestHandler.java b/src/main/java/ai/devchat/devchat/handler/ListModelsRequestHandler.java new file mode 100644 index 0000000..1fc6385 --- /dev/null +++ b/src/main/java/ai/devchat/devchat/handler/ListModelsRequestHandler.java @@ -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 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; + } +}