Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An OpenAI GPT-3 API client enabling Go/Golang programs to interact with the gpt3 APIs.

License

NotificationsYou must be signed in to change notification settings

PullRequestInc/go-gpt3

Repository files navigation

An OpenAI GPT-3 API client enabling Go/Golang programs to interact with the gpt3 APIs.

Supports using the completion APIs with or without streaming.

PkgGoDev

Usage

Simple usage to call the main gpt-3 API, completion:

client:=gpt3.NewClient(apiKey)resp,err:=client.Completion(ctx, gpt3.CompletionRequest{Prompt: []string{"2, 3, 5, 7, 11,"},})fmt.Print(resp.Choices[0].Text)// prints " 13, 17, 19, 23, 29, 31", etc

Documentation

Check out the go docs for more detailed documentation on the types and methods provided:https://pkg.go.dev/github.com/PullRequestInc/go-gpt3

Full Examples

Try out any of these examples with putting the contents in amain.go and runninggo run main.go.I would recommend using go modules in which case you will also need to rungo mod init within yourtest repo. Alternatively you can clone this repo and run the test script withgo run cmd/test/main.go.

You will also need to have a.env file that looks like this to use these examples:

API_KEY=<openAI API Key>
package mainimport ("context""fmt""log""os""github.com/PullRequestInc/go-gpt3""github.com/joho/godotenv")funcmain() {godotenv.Load()apiKey:=os.Getenv("API_KEY")ifapiKey=="" {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,})iferr!=nil {log.Fatalln(err)}fmt.Println(resp.Choices[0].Text)}

Support

  • List Engines API
  • Get Engine API
  • Completion API (this is the main gpt-3 API)
  • Streaming support for the Completion API
  • Document Search API
  • Overriding default url, user-agent, timeout, and other options

Powered by

About

An OpenAI GPT-3 API client enabling Go/Golang programs to interact with the gpt3 APIs.

Topics

Resources

License

Stars

Watchers

Forks

Contributors13

Languages


[8]ページ先頭

©2009-2025 Movatter.jp