From 3ec14cc65f8d9e33dd5f9d8c24fff3404862479b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 3 Dec 2022 19:56:58 -0600 Subject: [PATCH] more stuff --- example-gpt-3/Makefile | 5 +++-- example-gpt-3/{complicated.go => complicated} | 12 +++++++---- example-gpt-3/curl-2nd-grader.sh | 12 +++++++++++ example-gpt-3/curl-college.sh | 12 +++++++++++ example-gpt-3/curl-test-api-key.sh | 14 +++++++++++++ example-gpt-3/curl-test2.sh | 13 ++++++++++++ example-gpt-3/main.go | 20 +++++++++++++++++++ 7 files changed, 82 insertions(+), 6 deletions(-) rename example-gpt-3/{complicated.go => complicated} (95%) create mode 100644 example-gpt-3/curl-2nd-grader.sh create mode 100644 example-gpt-3/curl-college.sh create mode 100644 example-gpt-3/curl-test2.sh diff --git a/example-gpt-3/Makefile b/example-gpt-3/Makefile index a44c6b2..c264b63 100644 --- a/example-gpt-3/Makefile +++ b/example-gpt-3/Makefile @@ -1,7 +1,8 @@ build: # reset - GO111MODULE="off" go build -v -x complicated.go - # GO111MODULE="off" go build -v -x + # GO111MODULE="off" go build -v -x complicated.go + GO111MODULE="off" go build -v -x + ./example-gpt-3 deps: go get github.com/openai/gpt-3 diff --git a/example-gpt-3/complicated.go b/example-gpt-3/complicated similarity index 95% rename from example-gpt-3/complicated.go rename to example-gpt-3/complicated index 96dda93..97083f2 100644 --- a/example-gpt-3/complicated.go +++ b/example-gpt-3/complicated @@ -5,9 +5,14 @@ package main */ import ( - "fmt" - "github.com/openai/gpt-3" - "time" + "time" + "context" + "fmt" + "log" + "os" + + "github.com/PullRequestInc/go-gpt3" + "github.com/joho/godotenv" ) func main() { @@ -81,4 +86,3 @@ func main() { log.Println("i, c =", i, c) } } - diff --git a/example-gpt-3/curl-2nd-grader.sh b/example-gpt-3/curl-2nd-grader.sh new file mode 100644 index 0000000..25b7099 --- /dev/null +++ b/example-gpt-3/curl-2nd-grader.sh @@ -0,0 +1,12 @@ +curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "text-davinci-003", + "prompt": "Summarize this for a second-grade student:\n\nJupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.", + "temperature": 0.7, + "max_tokens": 64, + "top_p": 1.0, + "frequency_penalty": 0.0, + "presence_penalty": 0.0 +}' diff --git a/example-gpt-3/curl-college.sh b/example-gpt-3/curl-college.sh new file mode 100644 index 0000000..25b7099 --- /dev/null +++ b/example-gpt-3/curl-college.sh @@ -0,0 +1,12 @@ +curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "text-davinci-003", + "prompt": "Summarize this for a second-grade student:\n\nJupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.", + "temperature": 0.7, + "max_tokens": 64, + "top_p": 1.0, + "frequency_penalty": 0.0, + "presence_penalty": 0.0 +}' diff --git a/example-gpt-3/curl-test-api-key.sh b/example-gpt-3/curl-test-api-key.sh index f67545a..295571f 100755 --- a/example-gpt-3/curl-test-api-key.sh +++ b/example-gpt-3/curl-test-api-key.sh @@ -16,3 +16,17 @@ curl https://api.openai.com/v1/completions \ "presence_penalty": 0.0, "stop": ["\n"] }' + +curl https://api.openai.com/v1/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d '{ + "model": "text-davinci-003", + "prompt": "What color is the sky?", + "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/curl-test2.sh b/example-gpt-3/curl-test2.sh new file mode 100644 index 0000000..22c2eb3 --- /dev/null +++ b/example-gpt-3/curl-test2.sh @@ -0,0 +1,13 @@ +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/main.go b/example-gpt-3/main.go index 4320ba9..6bfed9b 100644 --- a/example-gpt-3/main.go +++ b/example-gpt-3/main.go @@ -9,6 +9,7 @@ import ( "github.com/PullRequestInc/go-gpt3" "github.com/joho/godotenv" ) +import "github.com/davecgh/go-spew/spew" func main() { godotenv.Load() @@ -22,6 +23,10 @@ func main() { ctx := context.Background() client := gpt3.NewClient(apiKey) + eng, _ := client.Engines(ctx) + log.Println("engines =", eng) + spew.Dump(eng) + resp, err := client.Completion(ctx, gpt3.CompletionRequest{ Prompt: []string{"The first thing you should know about javascript is"}, MaxTokens: gpt3.IntPtr(30), @@ -32,4 +37,19 @@ func main() { log.Fatalln(err) } fmt.Println(resp.Choices[0].Text) + spew.Dump(resp) + + /* + 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) + */ }