Package openai provides a Go SDK for the OpenAI API.this package supports several models, including GPT-4, GPT-3.5, GPT-3, DALL-E, and audio
models. You can specify the desired model using the Model
field in the request object.
- ChatGPT (GPT-3, GPT-3.5, GPT-4)
- DALL·E 2
- Embedding
- Audio
- Fine-Tune
- File
- Moderations
- Completion Patterns
- Multiple API keys support
$ go get -u github.com/GeniusAI-Platform/openai
package main
import (
"context"
"github.com/GeniusAI-Platform/openai"
"github.com/GeniusAI-Platform/openai/client"
"github.com/GeniusAI-Platform/openai/entity"
"github.com/GeniusAI-Platform/openai/models"
"log"
"os"
)
func main() {
apiKey := os.Getenv("OPENAI_API_KEY")
cli, err := client.New([]string{apiKey})
if err != nil {
log.Fatalln(err)
}
c := openai.NewCompletion(cli)
resp, err := c.CreateCompletion(context.Background(), entity.CompletionRequest{
Model: models.TEXT_DAVINCI_002,
Prompt: "can you explain bubble sort algorithm?",
})
if err != nil {
log.Fatalln(err)
}
log.Println(resp)
}
Example Completion Patterns
package main
import (
"context"
"github.com/GeniusAI-Platform/openai"
"github.com/GeniusAI-Platform/openai/client"
"github.com/GeniusAI-Platform/openai/patterns/completion"
"github.com/GeniusAI-Platform/openai/types/programming"
"log"
"os"
)
var code string = `
func add(a, b int) int {
return a + b
}
`
func main() {
apiKey := os.Getenv("OPENAI_API_KEY")
cli, err := client.New([]string{apiKey})
if err != nil {
log.Fatalln(err)
}
c := openai.NewCompletion(cli)
resp, err := c.CreateCompletionFromPattern(context.Background(), completion.ProgrammingLanguageTranslator(
code,
programming.Go,
programming.Python,
0,
))
if err != nil {
log.Fatalln(err)
}
log.Println(resp.Choices[0].Text)
}
See more details in documentation.
- Stream Support
- Moderation API
- Example API
- Fine-Tune API
- File API
- Engine API
- Azure API Support
- Client, API Unit test
- fork project in your GitHub account.
- create new branch for new changes.
- after change code, send Pull Request.