Skip to content

Commit

Permalink
add get me, prompt library and gizmos api
Browse files Browse the repository at this point in the history
  • Loading branch information
leokwsw committed Mar 25, 2024
1 parent 1cc49c3 commit 5db44cd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
39 changes: 37 additions & 2 deletions api/chatgpt/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,46 @@ func ClearConversations(c *gin.Context) {
}

func GetModels(c *gin.Context) {
handleGet(c, ApiPrefix+"/models", getModelsErrorMessage)

historyAndTrainingDisabled, ok := c.GetQuery("history_and_training_disabled")
if !ok {
historyAndTrainingDisabled = "false"
}

handleGet(c, ApiPrefix+"/models?history_and_training_disabled="+historyAndTrainingDisabled, getModelsErrorMessage)
}

func GetAccountCheck(c *gin.Context) {
handleGet(c, ApiPrefix+"/accounts/check", getAccountCheckErrorMessage)
handleGet(c, ApiPrefix+"/accounts/check/v4-2023-04-27", getAccountCheckErrorMessage)
}

func GetMe(c *gin.Context) {
handleGet(c, ApiPrefix+"/me", meErrorMessage)
}

func GetPromptLibrary(c *gin.Context) {

limit, ok := c.GetQuery("limit")
if !ok {
limit = "4"
}

offset, ok := c.GetQuery("offset")
if !ok {
offset = "0"
}

handleGet(c, ApiPrefix+"/prompt_library/?limit="+limit+"&offset="+offset, promptLibraryErrorMessage)
}

func GetGizmos(c *gin.Context) {
limit, ok := c.GetQuery("limit")
if !ok {
limit = "4"
}

handleGet(c, ApiPrefix+"/gizmos/bootstrap?limit="+limit, gizmosErrorMessage)

}

func handleNoAuthGet(c *gin.Context, url string, errorMessage string) {
Expand Down
3 changes: 3 additions & 0 deletions api/chatgpt/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const (
clearConversationsErrorMessage = "Failed to clear conversations."
feedbackMessageErrorMessage = "Failed to add feedback."
getModelsErrorMessage = "Failed to get models."
meErrorMessage = "Failed to get me"
promptLibraryErrorMessage = "Failed to get Prompt Library"
gizmosErrorMessage = "Failed to get Gizmos"
getAccountCheckErrorMessage = "Check failed." // Placeholder. Never encountered.
parseJsonErrorMessage = "Failed to parse json request body."

Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ func setupChatGPTAPIs(router *gin.Engine) {
// misc
chatgptGroup.GET("/models", chatgpt.GetModels)
chatgptGroup.GET("/accounts/check", chatgpt.GetAccountCheck)
chatgptGroup.GET("/me", chatgpt.GetMe)
chatgptGroup.GET("/prompt_library/", chatgpt.GetPromptLibrary)
chatgptGroup.GET("/gizmos", chatgpt.GetGizmos)

chatgptGroup.GET("/ping", chatgpt.Ping)
}
Expand Down

0 comments on commit 5db44cd

Please sign in to comment.