Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ak9024/go-chatgpt-sdk
This Library Provides Unofficial Go Client SDK for OpenAI API
https://github.com/ak9024/go-chatgpt-sdk
chatgpt chatgpt-sdk go golang sdk
Last synced: 12 days ago
JSON representation
This Library Provides Unofficial Go Client SDK for OpenAI API
- Host: GitHub
- URL: https://github.com/ak9024/go-chatgpt-sdk
- Owner: ak9024
- License: mit
- Created: 2023-07-18T03:26:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-26T02:30:21.000Z (3 months ago)
- Last Synced: 2024-08-26T03:40:53.230Z (3 months ago)
- Topics: chatgpt, chatgpt-sdk, go, golang, sdk
- Language: Go
- Homepage:
- Size: 116 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ak9024/go-chatgpt-sdk/.github%2Fworkflows%2Ftest.yml)
![GitHub top language](https://img.shields.io/github/languages/top/ak9024/go-chatgpt-sdk)
![GitHub License](https://img.shields.io/github/license/ak9024/go-chatgpt-sdk)# go-chatgpt-sdk
This Library Provides Unofficial Go Client SDK for OpenAI API
### Install
```bash
go get -u github.com/ak9024/go-chatgpt-sdk
```### Model Support
- [x] Chat
- [x] Text
- [x] Image
- [ ] Moderations
- [ ] Audio### Prerequisite
- [Go](https://go.dev/doc/install)
- [OpenAI Key](https://platform.openai.com/account/api-keys)### Usage with model chat
> to usage with model chat, please usage `c.ChatCompletions`
```go
package mainimport (
"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)
}
```### Usage with model text
> To usage with model text, please usage `c.Completions()`
```go
package mainimport (
"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)
}
```### Usage with model images
> Create images, please use `c.ImagesGenerations`, but if you want generate base64 image usage `c.ImageGenerationsB64JSON`
```go
package mainimport (
"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 usage `c.ImageVariationsB64JSON`
```go
package mainimport (
"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](./response.go)