Zero dependency (Unofficial) Go Client for OpenAI API endpoints. Built upon the great work done here.
Why did we bother to refactor the original library? We have 5 main goals:
- Use more idiomatic Go style.
- Better documentation.
- Make request parameters whose Go default value is a valid parameter value (and differs from OpenAI's defaults) pointers (See here for more).
- Have a consistent style throughout.
- Implement all endpoints.
We hope that by doing the above, future maintenance should also be trivial. Read more on the original refactoring PR here.
go get github.com/fabiustech/openai
package main
import (
"context"
"fmt"
"os"
"github.com/fabiustech/openai"
"github.com/fabiustech/openai/models"
"github.com/fabiustech/openai/params"
)
func main() {
var key, ok = os.LookupEnv("OPENAI_API_KEY")
if !ok {
panic("env variable OPENAI_API_KEY not set")
}
var c = openai.NewClient(key)
var resp, err = c.CreateCompletion(context.Background(), &openai.CompletionRequest[models.Completion]{
Model: models.TextDavinci003,
MaxTokens: 100,
Prompt: "Lorem ipsum",
Temperature: params.Optional(0.0),
})
if err != nil {
return
}
fmt.Println(resp.Choices[0].Text)
}
Contributions are welcome and encouraged! Feel free to report any bugs / feature requests as issues.