feat: support messages to ask AI (#1380)

This commit is contained in:
boojack
2023-03-18 22:07:14 +08:00
committed by GitHub
parent 8b20cb9fd2
commit 573f07ec82
8 changed files with 99 additions and 108 deletions

View File

@ -24,7 +24,7 @@ type ChatCompletionResponse struct {
Choices []ChatCompletionChoice `json:"choices"`
}
func PostChatCompletion(prompt string, apiKey string, apiHost string) (string, error) {
func PostChatCompletion(messages []ChatCompletionMessage, apiKey string, apiHost string) (string, error) {
if apiHost == "" {
apiHost = "https://api.openai.com"
}
@ -34,8 +34,12 @@ func PostChatCompletion(prompt string, apiKey string, apiHost string) (string, e
}
values := map[string]interface{}{
"model": "gpt-3.5-turbo",
"messages": []map[string]string{{"role": "user", "content": prompt}},
"model": "gpt-3.5-turbo",
"messages": messages,
"max_tokens": 2000,
"temperature": 0,
"frequency_penalty": 0.0,
"presence_penalty": 0.0,
}
jsonValue, err := json.Marshal(values)
if err != nil {