-
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.
Signed-off-by: Daniel Hu <[email protected]>
- Loading branch information
1 parent
0bbd607
commit 7df12ae
Showing
11 changed files
with
220 additions
and
46 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
## Get Setting | ||
|
||
### JS to Java | ||
|
||
```json | ||
{ | ||
"action": "getSetting/request", | ||
"metadata": { | ||
"callback": "responseFunctionName" | ||
}, | ||
"payload": null | ||
} | ||
``` | ||
|
||
### Java to JS | ||
|
||
- success | ||
|
||
```json | ||
{ | ||
"action": "getSetting/response", | ||
"metadata": { | ||
"status": "success", | ||
"error": "" | ||
}, | ||
"payload": { | ||
"setting": { | ||
"apiKey": "DC.abcdef123456", | ||
"apiBase": "https://api.example.com/v1", | ||
"currentModel": "gpt-4" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
- failed | ||
|
||
```json | ||
{ | ||
"action": "getSetting/response", | ||
"metadata": { | ||
"status": "Failed", | ||
"error": "Failed to get setting." | ||
}, | ||
"payload": null | ||
} | ||
``` | ||
|
||
## Set or Update Setting | ||
|
||
### JS to Java | ||
|
||
```json | ||
{ | ||
"action": "updateSetting/request", | ||
"metadata": { | ||
"callback": "responseFunctionName" | ||
}, | ||
"payload": { | ||
"setting": { | ||
"currentModel": "gpt-3.5" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Java to JS | ||
|
||
- success | ||
|
||
```json | ||
{ | ||
"action": "updateSetting/response", | ||
"metadata": { | ||
"status": "success", | ||
"error": "" | ||
}, | ||
"payload": null | ||
} | ||
``` | ||
|
||
- failed | ||
|
||
```json | ||
{ | ||
"action": "updateSetting/response", | ||
"metadata": { | ||
"status": "Failed", | ||
"error": "Failed to update setting." | ||
}, | ||
"payload": null | ||
} | ||
``` |
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
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
56 changes: 56 additions & 0 deletions
56
src/main/java/ai/devchat/devchat/handler/GetSettingRequestHandler.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,56 @@ | ||
package ai.devchat.devchat.handler; | ||
|
||
import ai.devchat.devchat.ActionHandler; | ||
import ai.devchat.devchat.DevChatActionHandler; | ||
import ai.devchat.devchat.DevChatActions; | ||
import ai.devchat.idea.setting.DevChatSettingsState; | ||
import ai.devchat.idea.storage.SensitiveDataStorage; | ||
import com.alibaba.fastjson.JSONObject; | ||
|
||
public class GetSettingRequestHandler implements ActionHandler { | ||
private JSONObject metadata; | ||
private JSONObject payload; | ||
private final DevChatActionHandler devChatActionHandler; | ||
|
||
public GetSettingRequestHandler(DevChatActionHandler devChatActionHandler) { | ||
this.devChatActionHandler = devChatActionHandler; | ||
} | ||
|
||
@Override | ||
public void executeAction() { | ||
String callbackFunc = metadata.getString("callback"); | ||
|
||
DevChatSettingsState settings = DevChatSettingsState.getInstance(); | ||
String apiKey = SensitiveDataStorage.getKey(); | ||
if (settings.apiBase == null || settings.apiBase.isEmpty()) { | ||
if (apiKey.startsWith("sk-")) { | ||
settings.apiBase = "https://api.openai.com/v1"; | ||
} else if (apiKey.startsWith("DC.")) { | ||
settings.apiBase = "https://api.devchat.ai/v1"; | ||
} | ||
} | ||
|
||
String apiBase = settings.apiBase; | ||
String currentModel = settings.defaultModel; | ||
|
||
devChatActionHandler.sendResponse(DevChatActions.GET_SETTING_RESPONSE, callbackFunc, (metadata, payload) -> { | ||
metadata.put("status", "success"); | ||
metadata.put("error", ""); | ||
JSONObject setting = new JSONObject(); | ||
setting.put("apiKey", apiKey); | ||
setting.put("apiBase", apiBase); | ||
setting.put("currentModel", currentModel); | ||
payload.put("setting", setting); | ||
}); | ||
} | ||
|
||
@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
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
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