OpenAI API wrapper library for Go.
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)
}
}
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.
All API functions so far (2023.11.07.) are implemented, but not all of them were tested on a paid account.
- Audio
- Chat
- Completions
- Embeddings
- Fine-tuning
- Files
- Images
- Models: works on a non-paid account
- Moderations: works on a non-paid account
Beta API functions require beta header like this:
client.SetBetaHeader(`assistants=v1`)
-
Stream(server-sent events) options are not implemented yet.thanks to @tectiv3 :-) - Add some sample applications.