Created
March 5, 2023 04:25
-
-
Save ernesto27/6aadbb2ed8169294c375505733381f16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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