From 63e089ced07dee00dd6f23128928acf1c32e0e7c Mon Sep 17 00:00:00 2001 From: Leo Wu Date: Sun, 7 Apr 2024 14:06:00 +0800 Subject: [PATCH] Added user settings and synthesize endpoints 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. --- api/chatgpt/api.go | 44 ++++++++++++++++++++++++++++++++++------- api/chatgpt/constant.go | 4 ++++ main.go | 11 +++++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/api/chatgpt/api.go b/api/chatgpt/api.go index 72b281070..c38ec55cf 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 7f7bfbea0..27e1bd6ec 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 ca14589e2..7041b593a 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)