modulepackage
1.6.4
Repository: https://github.com/go-zoox/chatgpt-client.git
Documentation: pkg.go.dev
# README
ChatGPT-Client is a ChatGPT Client with Offical OpenAI API.
Installation
To install the package, run:
go get -u github.com/go-zoox/chatgpt-client
Getting Started
Simple
package main
import (
"fmt"
"log"
"os"
_ "github.com/go-zoox/dotenv"
)
import (
chatgpt "github.com/go-zoox/chatgpt-client"
)
func main(t *testing.T) {
client, err := chatgpt.New(&Config{
APIKey: os.Getenv("API_KEY"),
})
if err != nil {
log.Fatal(err)
}
var question []byte
var answer []byte
question = []byte("OpenAI 是什么?")
fmt.Printf("question: %s\n", question)
answer, err = client.Ask(question)
if err != nil {
log.Fatal(err)
}
fmt.Printf("answer: %s\n\n", answer)
}
Use Conversation
package main
import (
"fmt"
"log"
"os"
_ "github.com/go-zoox/dotenv"
"github.com/go-zoox/uuid"
)
import (
chatgpt "github.com/go-zoox/chatgpt-client"
)
func main(t *testing.T) {
client, err := chatgpt.New(&Config{
APIKey: os.Getenv("API_KEY"),
})
if err != nil {
log.Fatal(err)
}
conversation, err := client.GetOrCreateConversation(uuid.V4(), &chatgpt.ConversationConfig{})
if err != nil {
log.Fatal(err)
}
var question []byte
var answer []byte
question = []byte("OpenAI 是什么?")
fmt.Printf("question: %s\n", question)
answer, err = conversation.Ask(question)
if err != nil {
log.Fatal(err)
}
fmt.Printf("answer: %s\n\n", answer)
question = []byte("可以展开讲讲吗?")
fmt.Printf("question: %s\n", question)
answer, err = conversation.Ask(question)
if err != nil {
log.Fatal(err)
}
fmt.Printf("answer: %s\n\n", answer)
question = []byte("我们现在讨论的内容是什么?")
fmt.Printf("question: %s\n", question)
answer, err = conversation.Ask(question)
if err != nil {
log.Fatal(err)
}
fmt.Printf("answer: %s\n\n", answer)
}
License
GoZoox is released under the MIT License.
# Constants
DefaultConversationMaxAge is timeout for each conversation.
DefaultMaxConversations is the default max conversation cache count.
DefaultMaxResponseTokens is the default response text max tokens.
# Variables
DefaultContext is the default context for instructions to ChatGPT.
DefaultContextIntl is the default context for instructions to ChatGPT.
Version is the version of this package.
# Structs
AskConfig ...
Config is the configuration for the ChatGPT Client.
ConversationAskConfig is the configuration for ask question.
ConversationConfig is the configuration for creating a new Conversation.
Message is a message.