36 lines
674 B
Go
36 lines
674 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"os"
|
||
|
|
||
|
"github.com/PullRequestInc/go-gpt3"
|
||
|
"github.com/joho/godotenv"
|
||
|
)
|
||
|
|
||
|
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)
|
||
|
|
||
|
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,
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
fmt.Println(resp.Choices[0].Text)
|
||
|
}
|