Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
fix: request body format in openai api (#1309)
boojackccf6af4dc388
diff --git a/plugin/openai/chat_completion.go b/plugin/openai/chat_completion.goindex b83147a95..221aa7a8c 100644--- a/plugin/openai/chat_completion.go+++ b/plugin/openai/chat_completion.go@@ -1,12 +1,12 @@package openaiimport (+ "bytes""encoding/json""errors""io""net/http""net/url"- "strings")type ChatCompletionMessage struct {@@ -25,10 +25,6 @@ type ChatCompletionResponse struct {}func PostChatCompletion(prompt string, apiKey string, apiHost string) (string, error) {- requestBody := strings.NewReader(`{- "model": "gpt-3.5-turbo",- "messages": [{"role": "user", "content": "` + prompt + `"}]- }`)if apiHost == "" {apiHost = "https://api.openai.com"}@@ -37,7 +33,16 @@ func PostChatCompletion(prompt string, apiKey string, apiHost string) (string, ereturn "", err}- req, err := http.NewRequest("POST", url, requestBody)+ values := map[string]interface{}{+ "model": "gpt-3.5-turbo",+ "messages": []map[string]string{{"role": "user", "content": prompt}},+ }+ jsonValue, err := json.Marshal(values)+ if err != nil {+ return "", err+ }++ req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonValue))if err != nil {return "", err}diff --git a/plugin/openai/text_completion.go b/plugin/openai/text_completion.goindex 25ce7dbfb..be7846ae5 100644--- a/plugin/openai/text_completion.go+++ b/plugin/openai/text_completion.go@@ -1,12 +1,12 @@package openaiimport (+ "bytes""encoding/json""errors""io""net/http""net/url"- "strings")type TextCompletionChoice struct {@@ -20,13 +20,6 @@ type TextCompletionResponse struct {}func PostTextCompletion(prompt string, apiKey string, apiHost string) (string, error) {- requestBody := strings.NewReader(`{- "prompt": "` + prompt + `",- "temperature": 0.5,- "max_tokens": 100,- "n": 1,- "stop": "."- }`)if apiHost == "" {apiHost = "https://api.openai.com"}@@ -35,7 +28,20 @@ func PostTextCompletion(prompt string, apiKey string, apiHost string) (string, ereturn "", err}- req, err := http.NewRequest("POST", url, requestBody)+ values := map[string]interface{}{+ "model": "gpt-3.5-turbo",+ "prompt": prompt,+ "temperature": 0.5,+ "max_tokens": 100,+ "n": 1,+ "stop": ".",+ }+ jsonValue, err := json.Marshal(values)+ if err != nil {+ return "", err+ }++ req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonValue))if err != nil {return "", err}