Go clients for OpenAI API
DO NOT USE THIS VERSION IN PRODUCTION, BECAUSE IT IS AN ALPHA VERSION
Import the appropriate library.
import "github.com/goloop/openai"
A personal client with default settings in can be quickly created using the New function.
apiKey := "sk-..."
client := openai.New(apiKey)
We can also add the Organization ID for the organization's client.
apiKey := "sk-..."
orgID := "org-..."
client := openai.New(apiKey, orgID)
We can set our own base URL of API, which can consist of several parts.
apiKey := "sk-..."
orgID := "org-..."
domain := "example.com"
v := "v1"
client := openai.New(apiKey, orgID, "https://", domain, v)
The client can be created with advanced configurations.
It is not necessary to specify all possible configuration parameters. Parameters not specified will be defined by default.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client := openai.New(openai.Config{
APIKey: "sk-...",
OrgID: "org-...",
Context: ctx,
ParallelTasks: 8,
})