Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/solywsh/chatgpt
chartgpt client for golang(use gpt3)
https://github.com/solywsh/chatgpt
Last synced: 3 months ago
JSON representation
chartgpt client for golang(use gpt3)
- Host: GitHub
- URL: https://github.com/solywsh/chatgpt
- Owner: solywsh
- License: mit
- Created: 2022-12-07T06:03:00.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-28T07:22:10.000Z (over 1 year ago)
- Last Synced: 2024-06-20T11:56:43.514Z (5 months ago)
- Language: Go
- Homepage:
- Size: 38.1 KB
- Stars: 25
- Watchers: 3
- Forks: 18
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chatgpt(use gpt3)
**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
## UsegeDownload the package first:
```shell
go get github.com/solywsh/chatgpt
```Conversation without context:
```go
package mainimport (
"fmt"
"github.com/solywsh/chatgpt"
"time"
)func main() {
// 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)
defer chat.Close()
//
//select {
//case <-chat.GetDoneChan():
// fmt.Println("time out/finish")
//}
question := "你认为2022年世界杯的冠军是谁?"
fmt.Printf("Q: %s\n", question)
answer, err := chat.Chat(question)
if err != nil {
fmt.Println(err)
}
fmt.Printf("A: %s\n", answer)//Q: 你认为2022年世界杯的冠军是谁?
//A: 这个问题很难回答,因为2022年世界杯还没有开始,所以没有人知道冠军是谁。
}```
Conversation with context:
```golang
package mainimport (
"fmt"
"github.com/solywsh/chatgpt"
"time"
)func main() {
chat := chatgpt.New("openai_key", "user_id(not required)", 10*time.Second)
defer chat.Close()
//select {
//case <-chat.GetDoneChan():
// fmt.Println("time out")
//}
question := "现在你是一只猫,接下来你只能用\"喵喵喵\"回答."
fmt.Printf("Q: %s\n", question)
answer, err := chat.ChatWithContext(question)
if err != nil {
fmt.Println(err)
}
fmt.Printf("A: %s\n", answer)
question = "你是一只猫吗?"
fmt.Printf("Q: %s\n", question)
answer, err = chat.ChatWithContext(question)
if err != nil {
fmt.Println(err)
}
fmt.Printf("A: %s\n", answer)// Q: 现在你是一只猫,接下来你只能用"喵喵喵"回答.
// A: 喵喵喵!
// Q: 你是一只猫吗?
// A: 喵喵~!
}
```