diff --git a/.gitignore b/.gitignore index e50c8ec..1003f00 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ myapi +gpt-cli-chat diff --git a/main.go b/main.go index 0cae09c..dde6cff 100644 --- a/main.go +++ b/main.go @@ -58,11 +58,11 @@ func main() { if *stdin_input { userInput, err := ioutil.ReadAll(os.Stdin) - message := buildMessage(string(userInput), *apiKey, float32(t), *model, *internet_access, *debug) - messages = append(messages, openai.UserMessage(string(message))) if err != nil { log.Fatal(err) } + message := buildMessage(string(userInput), *apiKey, float32(t), *model, *internet_access, *debug) + messages = append(messages, openai.UserMessage(string(message))) output, err := sendMessage(&client, messages, float32(t), *model) if err != nil { @@ -103,6 +103,10 @@ func sendMessage(client *openai.Client, messages []openai.ChatCompletionMessageP if err != nil { return "", err } + if len(chatCompletion.Choices) == 0 { + return "", fmt.Errorf("no choices returned from chat completion") + } + return chatCompletion.Choices[0].Message.Content, nil }