You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: Since openai released the api for chatgpt, it means that this repository is no longer of any practical use. If you wish to find a suitable package, you may consider this repository:https://github.com/sashabaranov/go-openai
Usege
Download the package first:
go get github.com/solywsh/chatgpt
Conversation without context:
package main
import (
"fmt""github.com/solywsh/chatgpt""time"
)
funcmain() {
// The timeout is used to control the situation that the session is in a long and multi session situation.// If it is set to 0, there will be no timeout. Note that a single request still has a timeout setting of 30s.chat:=chatgpt.New("openai_key", "user_id(not required)", 30*time.Second)
deferchat.Close()
////select {//case <-chat.GetDoneChan():// fmt.Println("time out/finish")//}question:="你认为2022年世界杯的冠军是谁?"fmt.Printf("Q: %s\n", question)
answer, err:=chat.Chat(question)
iferr!=nil {
fmt.Println(err)
}
fmt.Printf("A: %s\n", answer)
//Q: 你认为2022年世界杯的冠军是谁?//A: 这个问题很难回答,因为2022年世界杯还没有开始,所以没有人知道冠军是谁。
}