package main // https://chat.openai.com/chat import ( "context" "fmt" "log" "os" "github.com/PullRequestInc/go-gpt3" "github.com/joho/godotenv" ) import "github.com/davecgh/go-spew/spew" func main() { godotenv.Load() apiKey := os.Getenv("OPENAI_API_KEY") apiKey = "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" if apiKey == "" { log.Fatalln("Missing API KEY") } ctx := context.Background() client := gpt3.NewClient(apiKey) eng, _ := client.Engines(ctx) log.Println("engines =", eng) spew.Dump(eng) // shows how much things cost so far: // https://beta.openai.com/account/usage // shows the options you can pass in CompletionRequest: // https://pkg.go.dev/github.com/PullRequestInc/go-gpt3#CompletionRequest // resp, err := client.Completion(ctx, gpt3.CompletionRequest{ resp, err := client.CompletionWithEngine(ctx, "text-davinci-003", gpt3.CompletionRequest{ Prompt: []string{"Write a 3000 word essay about DiVinci"}, MaxTokens: gpt3.IntPtr(3000), Temperature: gpt3.Float32Ptr(0.7), TopP: gpt3.Float32Ptr(1), // PresencePenalty: gpt3.Float32(0), // FrequencyPenalty: gpt3.Float32(0), // Stop: []string{"."}, Echo: false, }) if err != nil { log.Fatalln(err) } fmt.Println("TEXT IS:", resp.Choices[0].Text) spew.Dump(resp) log.Println("TEXT IS:", resp.Choices[0].Text) /* resp, err = client.Completion(ctx, gpt3.CompletionRequest{ Prompt: []string{"The first thing you should know about javascript is"}, MaxTokens: gpt3.IntPtr(30), Stop: []string{"."}, Echo: true, Engine: "babbage", }) if err != nil { log.Fatalln(err) } fmt.Println(resp.Choices[0].Text) */ }