This Library Provides Unofficial Go Client SDK for OpenAI API
go get -u github.com/ak9024/go-chatgpt-sdk
- Chat
- Text
- Image
- Moderations
- Audio
to usage with model chat, please usage
c.ChatCompletions
package main
import (
"fmt"
gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)
func main() {
c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
OpenAIKey: "",
})
resp, _ := c.ChatCompletions(gochatgptsdk.ModelChat{
Model: "gpt-3.5-turbo",
Messages: []gochatgptsdk.Message{
{
Role: "system",
Content: "You are a Software engineer",
},
{
Role: "user",
Content: "Please create a simple function to using Go language",
},
},
})
fmt.Println(resp.Choices)
}
To usage with model text, please usage
c.Completions()
package main
import (
"fmt"
gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)
func main() {
c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
OpenAIKey: "",
})
resp, _ := c.Completions(gochatgptsdk.ModelText{
Model: "text-davinci-003",
Prompt: "What the weather Kota Palu for today?",
MaxTokens: 100, // max generates of word
})
fmt.Println(resp.Choices)
}
Create images, please use
c.ImagesGenerations
, but if you want generate base64 image usagec.ImageGenerationsB64JSON
package main
import (
"fmt"
gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)
func main() {
c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
OpenAIKey: "",
})
resp, _ := c.ImagesGenerations(gochatgptsdk.ModelImages{
Prompt: "Sunset sketch art",
N: 5, // generates 5 images
Size: gochatgptsdk.Size512, // with size 512x512
})
fmt.Println(resp.Data)
}
Create images variations of a given image, please use
c.ImagesVariations()
but if you want generate base64 image usagec.ImageVariationsB64JSON
package main
import (
"fmt"
gochatgptsdk "github.com/ak9024/go-chatgpt-sdk"
)
func main() {
c := gochatgptsdk.NewConfig(gochatgptsdk.Config{
OpenAIKey: "",
})
resp, _ := c.ImagesVariations(gochatgptsdk.ModelImagesVariations{
Image: "./path/to/example-img.png", // please suitable with your path image
N: "2", // generate 2 images
Size: gochatgptsdk.Size256, // with size 256x256
})
fmt.Println(resp.Data)
}
For all of response data please read more in file struct_response.go