diff --git a/.gitignore b/.gitignore index 2955ca5..579729d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ example-ui-table/example-ui-table autobuild/autobuild example-flag/example-flag +example-gpt-3/example-gpt-3 diff --git a/example-gpt-3/Makefile b/example-gpt-3/Makefile new file mode 100644 index 0000000..8386e72 --- /dev/null +++ b/example-gpt-3/Makefile @@ -0,0 +1,9 @@ +build: + # reset + GO111MODULE="off" go build -v -x + +deps: + go get github.com/openai/gpt-3 + +get: + GO111MODULE="off" go get -v -u . diff --git a/example-gpt-3/curl-test-api-key.sh b/example-gpt-3/curl-test-api-key.sh new file mode 100755 index 0000000..f67545a --- /dev/null +++ b/example-gpt-3/curl-test-api-key.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# + +export OPENAI_API_KEY=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 + +curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "text-davinci-003", + "prompt": "Convert this text to a programmatic command:\n\nExample: Ask Constance if we need some bread\nOutput: send-msg `find constance` Do we need some bread?\n\nReach out to the ski store and figure out if I can get my skis fixed before I leave on Thursday", + "temperature": 0, + "max_tokens": 100, + "top_p": 1.0, + "frequency_penalty": 0.2, + "presence_penalty": 0.0, + "stop": ["\n"] +}' diff --git a/example-gpt-3/generated-by-chatgpt b/example-gpt-3/generated-by-chatgpt new file mode 100644 index 0000000..fb22d57 --- /dev/null +++ b/example-gpt-3/generated-by-chatgpt @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "github.com/openai/gpt-3" +) + +func main() { + client := gpt3.NewClient("API_KEY") + res, err := client.Evaluate("Hello, world!") + if err != nil { + panic(err) + } + fmt.Println(res.Text) +} diff --git a/example-gpt-3/main.go b/example-gpt-3/main.go new file mode 100644 index 0000000..4320ba9 --- /dev/null +++ b/example-gpt-3/main.go @@ -0,0 +1,35 @@ +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) +}