Skip to content

Commit

Permalink
Added user settings and synthesize endpoints
Browse files Browse the repository at this point in the history
Three new API endpoints have been added to the chatgpt service: GetUserSetting, UpdateUserSetting, and GetSynthesize. The GetUserSetting and UpdateUserSetting functions allow for retrieval and modification of user settings respectively. The GetSynthesize function provides synthesized audio output based on given parameters. Additionally, some error messages related to these new functionalities have been defined in constants file. Also, the GetModels function has been simplified by removing a query parameter check.
  • Loading branch information
leokwsw committed Apr 7, 2024
1 parent cd33fef commit 63e089c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
44 changes: 37 additions & 7 deletions api/chatgpt/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,42 @@ import (
http2 "net/http"
)

func UpdateUserSetting(c *gin.Context) {
feature, ok := c.GetQuery("feature")
if !ok {
return
}
value, ok := c.GetQuery("value")
if !ok {
return
}
handlePatch(c, ApiPrefix+"/settings/account_user_setting?feature="+feature+"&value="+value, "{}", updateMySettingErrorMessage)
}

func GetUserSetting(c *gin.Context) {
handleGet(c, ApiPrefix+"/settings/user", getMySettingErrorMessage)
}

func GetSynthesize(c *gin.Context) {
conversationId, ok := c.GetQuery("conversation_id")
if !ok {
return
}
messageId, ok := c.GetQuery("message_id")
if !ok {
return
}
voice, ok := c.GetQuery("voice")
if !ok {
voice = "cove"
}
format, ok := c.GetQuery("format")
if !ok {
format = "aac"
}
handleGet(c, ApiPrefix+"/synthesize?conversation_id="+conversationId+"&message_id="+messageId+"&voice="+voice+"&format="+format, getSynthesizeErrorMessage)
}

func GetConversations(c *gin.Context) {
offset, ok := c.GetQuery("offset")
if !ok {
Expand Down Expand Up @@ -392,13 +428,7 @@ func ClearConversations(c *gin.Context) {
}

func GetModels(c *gin.Context) {

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

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

func GetAccountCheck(c *gin.Context) {
Expand Down
4 changes: 4 additions & 0 deletions api/chatgpt/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const (
conversationLimit = PublicApiPrefix + "/conversation_limit"
ApiPrefix = "https://chat.openai.com/backend-api"
AnonPrefix = "https://chat.openai.com/backend-anon"
updateMySettingErrorMessage = "Failed to update setting"
getMySettingErrorMessage = "Failed to get setting"
getSynthesizeErrorMessage = "Failed to get synthesize."
getConversationsErrorMessage = "Failed to get conversations."
generateTitleErrorMessage = "Failed to generate title."
getContentErrorMessage = "Failed to get content."
Expand All @@ -23,6 +26,7 @@ const (
gpt3dot5Model = "text-davinci-002-render-sha"

actionContinue = "continue"
actionVariant = "variant"
responseTypeMaxTokens = "max_tokens"
responseStatusFinishedSuccessfully = "finished_successfully"
noModelPermissionErrorMessage = "you have no permission to use this model"
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ func setupChatGPTAPIs(router *gin.Engine) {
conversationGroup.POST("/message_feedback", chatgpt.FeedbackMessage)
}

synthesizeGroup := chatgptGroup.Group("/synthesize")
{
synthesizeGroup.GET("/", chatgpt.GetSynthesize)
}

settingGroup := chatgptGroup.Group("/settings")
{
settingGroup.GET("/user", chatgpt.GetUserSetting)
settingGroup.PATCH("/account_user_setting", chatgpt.UpdateUserSetting)
}

// misc
chatgptGroup.GET("/models", chatgpt.GetModels)
chatgptGroup.GET("/accounts/check", chatgpt.GetAccountCheck)
Expand Down

0 comments on commit 63e089c

Please sign in to comment.