/openai-go

OpenAI API wrapper for golang

Primary LanguageGoOtherNOASSERTION

openai-go

OpenAI API wrapper library for Go.

How to use

Generate API key from here,

and get organization id from here.

const apiKey = "ab-cdefHIJKLMNOPQRSTUVWXYZ0123456789"
const orgID = "org-0123456789ABCDefghijklmnopQRSTUVWxyz"

func main() {
    client := NewClient(apiKey, orgID)

    if models, err := client.ListModels(); err != nil {
        log.Printf("available models = %+v", models.Data)
    }
}

How to test

Export following environment variables:

$ export OPENAI_API_KEY=ab-cdefHIJKLMNOPQRSTUVWXYZ0123456789
$ export OPENAI_ORGANIZATION=org-0123456789ABCDefghijklmnopQRSTUVWxyz

# for verbose messages and http request dumps,
$ export VERBOSE=true

and then

$ go test

CAUTION: It is advised to set usage limits before running tests; running all tests at once costs about ~$0.2.

Todos/WIP

Implemented

All API functions so far (2023.11.07.) are implemented, but not all of them were tested on a paid account.

Beta

Note

Beta API functions require beta header like this:

client.SetBetaHeader(`assistants=v1`)

Help Wanted

  • Stream(server-sent events) options are not implemented yet. thanks to @tectiv3 :-)
  • Add some sample applications.