Skip to content

Instantly share code, notes, and snippets.

@ernesto27
Created March 5, 2023 04:25
Show Gist options
  • Save ernesto27/6aadbb2ed8169294c375505733381f16 to your computer and use it in GitHub Desktop.
Save ernesto27/6aadbb2ed8169294c375505733381f16 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"context"
"fmt"
"os"
"github.com/sashabaranov/go-openai"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Ask to chat gpt: ")
text, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Error reading input:", err)
return
}
fmt.Println("Sending question to openaiAPI...")
c := openai.NewClient("youropenaitoken")
resp, err := c.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: openai.GPT3Dot5Turbo,
Messages: []openai.ChatCompletionMessage{
{
Role: "user",
Content: text,
},
},
},
)
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
fmt.Println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment