This library provides Go clients for OpenAI API.
Installation:
go get github.com/stone-stones/simpleGPT
Run Test:
go test -gcflags all=-l
ChatGPT example usage:
package main
import (
"fmt"
simpleGPT "github.com/stone-stones/simpleGPT"
)
func main() {
client, err := simpleGPT.NewClient("your_token")
if err != nil {
return
}
res, err := client.SendMsg("Who is the American president")
if err != nil {
return
}
fmt.Println(res)
//you can go on ask more question with pre questions
res, err = client.SendMsg("tell me about him")
if err != nil {
return
}
fmt.Println(res)
}
chatGPT stream message
package main
import (
"fmt"
simpleGPT "github.com/stone-stones/simpleGPT"
)
func main() {
client, err := simpleGPT.NewClient("your_token")
if err != nil {
return
}
res, err := client.SendStreamMsg("Who is the American president")
if err != nil {
return
}
fmt.Println(res)
//you can go on ask more question with pre questions
res, err = client.SendStreamMsg("tell me about him")
if err != nil {
return
}
fmt.Println(res)
}
chatGPT with config
package main
import (
"context"
"fmt"
simpleGPT "github.com/stone-stones/simpleGPT"
)
func main() {
err := simpleGPT.LoadConfigFromFile("path_to_your_config", simpleGPT.GetLogger())
if err != nil {
fmt.Println(err)
return
}
client, err := simpleGPT.NewClient()
if err != nil {
fmt.Println(err)
return
}
client.Ctx = context.Background()
resp, err := client.SendMsg("How to be rich")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp)
resp, err = client.SendMsg("what can I do to archive that?")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp)
}