diff --git a/api/chatgpt/api.go b/api/chatgpt/api.go index 72b28107..c38ec55c 100644 --- a/api/chatgpt/api.go +++ b/api/chatgpt/api.go @@ -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 { @@ -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) { diff --git a/api/chatgpt/constant.go b/api/chatgpt/constant.go index 7f7bfbea..27e1bd6e 100644 --- a/api/chatgpt/constant.go +++ b/api/chatgpt/constant.go @@ -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." @@ -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" diff --git a/main.go b/main.go index ca14589e..7041b593 100644 --- a/main.go +++ b/main.go @@ -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)