├── .gitignore ├── README.md ├── edgegpt ├── answer.go ├── chatbot.go ├── chathub.go ├── conversation.go ├── request.go └── utils.go ├── go.mod ├── go.sum └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | *.exe 3 | *.exe~ 4 | /data -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go-EdgeGPT 2 | 3 | Go-EdgeGPT is a New Bing unofficial API developed using Golang. With most chatbot APIs being built on Python, Go-EdgeGPT is unique in its ability to be easily compiled and deployed. It's designed to work seamlessly with your current applications, providing a customizable and reliable chatbot experience. 4 | 5 | ## Setup 6 | 7 | ``` 8 | go get -u github.com/billikeu/Go-EdgeGPT/edgegpt 9 | ``` 10 | 11 | ## Example bot 12 | 13 | ```golang 14 | package main 15 | 16 | import ( 17 | "log" 18 | 19 | "github.com/billikeu/Go-EdgeGPT/edgegpt" 20 | ) 21 | 22 | func callback(answer *edgegpt.Answer) { 23 | if answer.IsDone() { 24 | log.Println(answer.NumUserMessages(), answer.MaxNumUserMessages(), answer.Text()) 25 | } 26 | } 27 | 28 | func main() { 29 | log.SetFlags(log.LstdFlags | log.Lshortfile) 30 | bot := edgegpt.NewChatBot("cookie.json", []map[string]interface{}{}, "http://127.0.0.1:10809") 31 | err := bot.Init() 32 | if err != nil { 33 | panic(err) 34 | } 35 | err = bot.Ask("give me a joke", edgegpt.Creative, callback) 36 | if err != nil { 37 | panic(err) 38 | } 39 | err = bot.Ask("It's not funny", edgegpt.Creative, callback) 40 | if err != nil { 41 | panic(err) 42 | } 43 | } 44 | 45 | ``` 46 | 47 | ## Others 48 | 49 | - https://github.com/billikeu/Go-EdgeGPT 50 | - https://github.com/billikeu/Go-ChatBot 51 | - https://github.com/billikeu/ChatGPT-App 52 | - https://github.com/billikeu/go-chatgpt 53 | - https://github.com/billikeu/AIArchive 54 | 55 | ## Star History 56 | 57 | [![Star History Chart](https://api.star-history.com/svg?repos=billikeu/Go-EdgeGPT&type=Date)](https://star-history.com/#billikeu/Go-EdgeGPT&Date) 58 | 59 | ## Contributors 60 | 61 | This project exists thanks to all the people who contribute. 62 | 63 | 64 | 65 | 66 | 67 | ## Reference 68 | 69 | Thanks for [EdgeGPT](https://github.com/acheong08/EdgeGPT) 70 | -------------------------------------------------------------------------------- /edgegpt/answer.go: -------------------------------------------------------------------------------- 1 | package edgegpt 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | "time" 7 | 8 | "github.com/tidwall/gjson" 9 | ) 10 | 11 | type SuggestedResponses struct { 12 | Text string `json:"text"` 13 | Author string `json:"author"` 14 | CreatedAt time.Time `json:"createdAt"` 15 | Timestamp time.Time `json:"timestamp"` 16 | MessageID string `json:"messageId"` 17 | MessageType string `json:"messageType"` 18 | Offense string `json:"offense"` 19 | Feedback struct { 20 | Tag interface{} `json:"tag"` 21 | UpdatedOn interface{} `json:"updatedOn"` 22 | Type string `json:"type"` 23 | } `json:"feedback"` 24 | ContentOrigin string `json:"contentOrigin"` 25 | Privacy interface{} `json:"privacy"` 26 | } 27 | 28 | type Answer struct { 29 | msg string 30 | j gjson.Result 31 | done bool 32 | } 33 | 34 | func NewAnswer(msg string) *Answer { 35 | answer := &Answer{ 36 | msg: msg, 37 | j: gjson.Parse(msg), 38 | done: false, 39 | } 40 | return answer 41 | } 42 | 43 | func (answer *Answer) Raw() string { 44 | return answer.msg 45 | } 46 | 47 | func (answer *Answer) Text() string { 48 | if answer.Type() == 2 { 49 | messages := answer.j.Get("item.messages").Array() 50 | if len(messages) < 1 { 51 | return "" 52 | } 53 | lastMsg := messages[len(messages)-1].Get("text").String() 54 | if lastMsg == "" { 55 | lastMsg = messages[len(messages)-1].Get("hiddenText").String() 56 | } 57 | if lastMsg == "" { 58 | lastMsg = messages[len(messages)-1].Get("spokenText").String() 59 | } 60 | return lastMsg 61 | } 62 | arguments := answer.j.Get("arguments").Array() 63 | if len(arguments) < 1 { 64 | return "" 65 | } 66 | messages := arguments[0].Get("messages").Array() 67 | if len(messages) < 1 { 68 | return "" 69 | } 70 | adaptiveCards := messages[0].Get("adaptiveCards").Array() 71 | if len(adaptiveCards) < 1 { 72 | return "" 73 | } 74 | body := adaptiveCards[0].Get("body").Array() 75 | if len(body) < 1 { 76 | return "" 77 | } 78 | text := body[0].Get("text").String() 79 | return text 80 | } 81 | 82 | func (answer *Answer) Type() int64 { 83 | return answer.j.Get("type").Int() 84 | } 85 | 86 | func (answer *Answer) SetDone() { 87 | answer.done = true 88 | } 89 | 90 | func (answer *Answer) IsDone() bool { 91 | return answer.Type() == 2 92 | } 93 | 94 | func (answer *Answer) SuggestedRes() []SuggestedResponses { 95 | suggest := []SuggestedResponses{} 96 | if answer.Type() == 2 { 97 | messages := answer.j.Get("item.messages").Array() 98 | if len(messages) < 1 { 99 | return suggest 100 | } 101 | suggestedResponses := messages[len(messages)-1].Get("suggestedResponses").Array() 102 | for _, item := range suggestedResponses { 103 | s := SuggestedResponses{} 104 | err := json.Unmarshal([]byte(item.String()), &s) 105 | if err != nil { 106 | log.Println(err) 107 | continue 108 | } 109 | suggest = append(suggest, s) 110 | } 111 | return suggest 112 | } 113 | if answer.Type() == 1 { 114 | arguments := answer.j.Get("arguments").Array() 115 | if len(arguments) < 1 { 116 | return suggest 117 | } 118 | messages := arguments[0].Get("messages").Array() 119 | if len(messages) < 1 { 120 | return suggest 121 | } 122 | suggestedResponses := messages[len(messages)-1].Get("suggestedResponses").Array() 123 | for _, item := range suggestedResponses { 124 | s := SuggestedResponses{} 125 | err := json.Unmarshal([]byte(item.String()), &s) 126 | if err != nil { 127 | log.Println(err) 128 | continue 129 | } 130 | suggest = append(suggest, s) 131 | } 132 | return suggest 133 | } 134 | return suggest 135 | } 136 | 137 | func (answer *Answer) MaxNumUserMessages() int64 { 138 | return answer.j.Get("item.throttling.maxNumUserMessagesInConversation").Int() 139 | } 140 | 141 | func (answer *Answer) NumUserMessages() int64 { 142 | return answer.j.Get("item.throttling.numUserMessagesInConversation").Int() 143 | } 144 | -------------------------------------------------------------------------------- /edgegpt/chatbot.go: -------------------------------------------------------------------------------- 1 | package edgegpt 2 | 3 | import ( 4 | "log" 5 | ) 6 | 7 | // Combines everything to make it seamless 8 | type ChatBot struct { 9 | cookiePath string 10 | cookies []map[string]interface{} 11 | proxy string 12 | chatHub *ChatHub 13 | addr string 14 | path string 15 | } 16 | 17 | func NewChatBot(cookiePath string, cookies []map[string]interface{}, proxy string) *ChatBot { 18 | addr := "sydney.bing.com" 19 | path := "/sydney/ChatHub" 20 | bot := &ChatBot{ 21 | cookiePath: cookiePath, 22 | cookies: cookies, 23 | proxy: proxy, 24 | addr: addr, 25 | path: path, 26 | chatHub: nil, 27 | } 28 | return bot 29 | } 30 | 31 | func (bot *ChatBot) Init() error { 32 | conversation := NewConversation(bot.cookiePath, bot.cookies, bot.proxy) 33 | err := conversation.Init() 34 | if err != nil { 35 | return err 36 | } 37 | bot.chatHub = NewChatHub(bot.addr, bot.path, conversation) 38 | log.Println("init success") 39 | return nil 40 | } 41 | 42 | /* 43 | // Ask a question to the bot 44 | The callback function is streaming, 45 | it will be called every time data is received, 46 | if you only want to get the final result, 47 | you can use `answer.IsDone()` to judge whether it is finished 48 | */ 49 | func (bot *ChatBot) Ask(prompt string, conversationStyle ConversationStyle, callback func(answer *Answer)) error { 50 | // defer bot.chatHub.Close() 51 | err := bot.chatHub.newConnect() 52 | if err != nil { 53 | return err 54 | } 55 | defer bot.chatHub.Close() 56 | log.Println("connect chathub success") 57 | return bot.chatHub.askStream(prompt, conversationStyle, callback) 58 | } 59 | 60 | func (bot *ChatBot) Close() error { 61 | return bot.chatHub.Close() 62 | } 63 | 64 | // Reset the conversation 65 | func (bot *ChatBot) Reset() error { 66 | bot.chatHub.Close() 67 | err := bot.Init() 68 | if err != nil { 69 | return err 70 | } 71 | return nil 72 | } 73 | -------------------------------------------------------------------------------- /edgegpt/chathub.go: -------------------------------------------------------------------------------- 1 | package edgegpt 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | "net/url" 8 | 9 | "github.com/gorilla/websocket" 10 | ) 11 | 12 | // http.Header{} 13 | var HEADERS = map[string]string{ 14 | "accept": "application/json", 15 | "accept-language": "en-US,en;q=0.9", 16 | "content-type": "application/json", 17 | "sec-ch-ua": `"Not_A Brand";v="99", "Microsoft Edge";v="110", "Chromium";v="110"`, 18 | "sec-ch-ua-arch": `"x86"`, 19 | "sec-ch-ua-bitness": `"64"`, 20 | "sec-ch-ua-full-version": `"109.0.1518.78"`, 21 | "sec-ch-ua-full-version-list": `"Chromium";v="110.0.5481.192", "Not A(Brand";v="24.0.0.0", "Microsoft Edge";v="110.0.1587.69"`, 22 | "sec-ch-ua-mobile": "?0", 23 | "sec-ch-ua-model": "", 24 | "sec-ch-ua-platform": `"Windows"`, 25 | "sec-ch-ua-platform-version": `"15.0.0"`, 26 | "sec-fetch-dest": "empty", 27 | "sec-fetch-mode": "cors", 28 | "sec-fetch-site": "same-origin", 29 | "x-ms-client-request-id": GetUuidV4(), 30 | "x-ms-useragent": "azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.0 OS/Win32", 31 | "Referer": "https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx", 32 | "Referrer-Policy": "origin-when-cross-origin", 33 | "x-forwarded-for": GetRandomIp(), 34 | } 35 | 36 | // Chat API 37 | type ChatHub struct { 38 | // hub *Hub 39 | addr string 40 | path string 41 | done chan struct{} 42 | // The websocket connection. 43 | ws *websocket.Conn 44 | request *ChatHubRequest 45 | } 46 | 47 | func NewChatHub(addr, path string, conversation *Conversation) *ChatHub { 48 | chathub := &ChatHub{ 49 | addr: addr, 50 | path: path, 51 | done: make(chan struct{}), 52 | request: NewChatHubRequest( 53 | conversation.Struct["conversationSignature"].(string), 54 | conversation.Struct["clientId"].(string), 55 | conversation.Struct["conversationId"].(string), 56 | 0, 57 | ), 58 | } 59 | return chathub 60 | } 61 | 62 | func (chathub *ChatHub) newConnect() error { 63 | u := url.URL{ 64 | Scheme: "wss", 65 | Host: chathub.addr, 66 | Path: chathub.path, 67 | } 68 | headers := http.Header{} 69 | for key, value := range HEADERS { 70 | headers.Add(key, value) 71 | } 72 | log.Printf("connecting to %s", u.String()) 73 | c, _, err := websocket.DefaultDialer.Dial(u.String(), headers) 74 | if err != nil { 75 | log.Fatal("dial:", err) 76 | } 77 | chathub.ws = c 78 | return nil 79 | } 80 | 81 | func (chathub *ChatHub) Close() error { 82 | return chathub.ws.Close() 83 | } 84 | 85 | func (chathub *ChatHub) initialHandshake() error { 86 | msg, err := appendIdentifier(map[string]interface{}{"protocol": "json", "version": 1}) 87 | if err != nil { 88 | return fmt.Errorf("initialHandshake err: %s", err.Error()) 89 | } 90 | err = chathub.ws.WriteMessage(websocket.TextMessage, []byte(msg)) 91 | if err != nil { 92 | return fmt.Errorf("initialHandshake write err: %s", err.Error()) 93 | } 94 | _, message, err := chathub.ws.ReadMessage() 95 | if err != nil { 96 | return fmt.Errorf("initialHandshake err: %v %s", message, err.Error()) 97 | } 98 | return nil 99 | } 100 | 101 | // Ask a question to the bot 102 | func (chathub *ChatHub) askStream(prompt string, conversationStyle ConversationStyle, callback func(answer *Answer)) error { 103 | err := chathub.initialHandshake() 104 | if err != nil { 105 | return err 106 | } 107 | log.Println("initialHandshake success") 108 | // Construct a ChatHub request 109 | chathub.request.Update(prompt, conversationStyle) 110 | // Send request 111 | msg, err := appendIdentifier(chathub.request.Struct) 112 | if err != nil { 113 | return fmt.Errorf("appendIdentifier request struct err: %s", err.Error()) 114 | } 115 | chathub.ws.WriteMessage(websocket.TextMessage, []byte(msg)) 116 | // var final bool = false 117 | for { 118 | _, message, err := chathub.ws.ReadMessage() 119 | if err != nil { 120 | return err 121 | } 122 | if string(message) == "" { 123 | return nil 124 | } 125 | answer := NewAnswer(string(message)) 126 | if callback != nil { 127 | callback(answer) 128 | } 129 | if answer.IsDone() { 130 | return nil 131 | } 132 | if answer.Type() != 1 && answer.Type() != 2 { 133 | log.Println(answer.Raw()) 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /edgegpt/conversation.go: -------------------------------------------------------------------------------- 1 | package edgegpt 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | "net/http" 9 | "os" 10 | "time" 11 | 12 | "github.com/go-resty/resty/v2" 13 | "github.com/tidwall/gjson" 14 | ) 15 | 16 | var HEADERS_INIT_CONVER = map[string]string{ 17 | "authority": "edgeservices.bing.com", 18 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", 19 | "accept-language": "en-US,en;q=0.9", 20 | "cache-control": "max-age=0", 21 | "sec-ch-ua": `"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"`, 22 | "sec-ch-ua-arch": `"x86"`, 23 | "sec-ch-ua-bitness": `"64"`, 24 | "sec-ch-ua-full-version": `"110.0.1587.69"`, 25 | "sec-ch-ua-full-version-list": `"Chromium";v="110.0.5481.192", "Not A(Brand";v="24.0.0.0", "Microsoft Edge";v="110.0.1587.69"`, 26 | "sec-ch-ua-mobile": "?0", 27 | "sec-ch-ua-model": `""`, 28 | "sec-ch-ua-platform": `"Windows"`, 29 | "sec-ch-ua-platform-version": `"15.0.0"`, 30 | "sec-fetch-dest": "document", 31 | "sec-fetch-mode": "navigate", 32 | "sec-fetch-site": "none", 33 | "sec-fetch-user": "?1", 34 | "upgrade-insecure-requests": "1", 35 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.69", 36 | "x-edge-shopping-flag": "1", 37 | "x-forwarded-for": "1.1.1.1", 38 | } 39 | 40 | // Conversation API 41 | type Conversation struct { 42 | Struct map[string]interface{} 43 | Session *resty.Request 44 | cookiePath string 45 | cookies []map[string]interface{} 46 | proxy string 47 | } 48 | 49 | func NewConversation(cookiePath string, cookies []map[string]interface{}, proxy string) *Conversation { 50 | con := &Conversation{ 51 | Struct: map[string]interface{}{ 52 | "conversationId": "", 53 | "clientId": "", 54 | "conversationSignature": "", 55 | "result": map[string]string{ 56 | "value": "Success", 57 | "message": "", 58 | }, 59 | }, 60 | cookiePath: cookiePath, 61 | cookies: cookies, 62 | proxy: proxy, 63 | } 64 | return con 65 | } 66 | 67 | func (con *Conversation) Init() error { 68 | // session 69 | client := resty.New() 70 | if con.proxy != "" { 71 | client.SetProxy(con.proxy) 72 | } 73 | client.SetTimeout(time.Second * 30) 74 | con.Session = client.R(). 75 | SetHeaders(HEADERS_INIT_CONVER) 76 | 77 | // set cookies 78 | if con.cookies == nil { 79 | con.cookies = []map[string]interface{}{} 80 | } 81 | if len(con.cookies) == 0 { 82 | b, err := ioutil.ReadFile(con.cookiePath) 83 | if err != nil { 84 | return err 85 | } 86 | err = json.Unmarshal(b, &con.cookies) 87 | if err != nil { 88 | return err 89 | } 90 | } 91 | for _, item := range con.cookies { 92 | con.Session.SetCookie(&http.Cookie{ 93 | Name: item["name"].(string), 94 | Value: item["value"].(string), 95 | }) 96 | } 97 | // Send GET request 98 | url := os.Getenv("BING_PROXY_URL") 99 | if url == "" { 100 | url = "https://edgeservices.bing.com/edgesvc/turing/conversation/create" 101 | } 102 | resp, err := con.Session.Get(url) 103 | if err != nil { 104 | return fmt.Errorf("init conversation err:%s", err.Error()) 105 | } 106 | if resp.StatusCode() != 200 { 107 | log.Println(resp.String()) 108 | return fmt.Errorf("conversation authentication failed: %d", resp.StatusCode()) 109 | } 110 | 111 | // log.Println("conversation info:", resp.String()) 112 | j := gjson.Parse(resp.String()) 113 | if j.Get("result.value").String() == "UnauthorizedRequest" { 114 | return fmt.Errorf("conversation err:%s", j.Get("result.message").String()) 115 | } 116 | err = json.Unmarshal([]byte(resp.String()), &con.Struct) 117 | if err != nil { 118 | return fmt.Errorf("init conversation err:%s", err.Error()) 119 | } 120 | return nil 121 | 122 | } 123 | -------------------------------------------------------------------------------- /edgegpt/request.go: -------------------------------------------------------------------------------- 1 | package edgegpt 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type ConversationStyle string 8 | 9 | const ( 10 | Creative ConversationStyle = "h3relaxedimg" 11 | Balanced ConversationStyle = "galileo" 12 | Precise ConversationStyle = "h3precise" 13 | ) 14 | 15 | // Request object for ChatHub 16 | type ChatHubRequest struct { 17 | Struct map[string]interface{} 18 | ConversationSignature string 19 | ClientId string 20 | ConversationId string 21 | InvocationId int 22 | } 23 | 24 | func NewChatHubRequest(conversationSignature, clientId, conversationId string, invocationId int) *ChatHubRequest { 25 | req := &ChatHubRequest{ 26 | Struct: map[string]interface{}{}, 27 | ConversationSignature: conversationSignature, 28 | ConversationId: conversationId, 29 | ClientId: clientId, 30 | InvocationId: invocationId, 31 | } 32 | return req 33 | } 34 | 35 | // Updates request object 36 | func (req *ChatHubRequest) Update(prompt string, conversation_style ConversationStyle, options ...string) { 37 | if len(options) == 0 { 38 | options = []string{ 39 | "deepleo", 40 | "enable_debug_commands", 41 | "disable_emoji_spoken_text", 42 | "enablemm", 43 | } 44 | } 45 | if conversation_style != "" { 46 | options = []string{ 47 | "nlu_direct_response_filter", 48 | "deepleo", 49 | "disable_emoji_spoken_text", 50 | "responsible_ai_policy_235", 51 | "enablemm", 52 | string(conversation_style), 53 | "dtappid", 54 | "cricinfo", 55 | "cricinfov2", 56 | "dv3sugg", 57 | } 58 | } 59 | req.Struct = map[string]interface{}{ 60 | "arguments": []interface{}{ 61 | map[string]interface{}{ 62 | "source": "cib", 63 | "optionsSets": options, 64 | "sliceIds": []interface{}{ 65 | "222dtappid", 66 | "225cricinfo", 67 | "224locals0", 68 | }, 69 | "traceId": GetRandomHex(32), 70 | "isStartOfSession": req.InvocationId == 0, 71 | "message": map[string]interface{}{ 72 | "author": "user", 73 | "inputMethod": "Keyboard", 74 | "text": prompt, 75 | "messageType": "Chat", 76 | }, 77 | "conversationSignature": req.ConversationSignature, 78 | "participant": map[string]interface{}{ 79 | "id": req.ClientId, 80 | }, 81 | "conversationId": req.ConversationId, 82 | }, 83 | }, 84 | "invocationId": fmt.Sprintf("%d", req.InvocationId), 85 | "target": "chat", 86 | "type": 4, 87 | } 88 | req.InvocationId += 1 89 | } 90 | -------------------------------------------------------------------------------- /edgegpt/utils.go: -------------------------------------------------------------------------------- 1 | package edgegpt 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "math/rand" 7 | "time" 8 | 9 | uuid "github.com/satori/go.uuid" 10 | ) 11 | 12 | var DELIMITER string = "\x1e" 13 | 14 | // Appends special character to end of message to identify end of message 15 | func appendIdentifier(msg map[string]interface{}) (string, error) { 16 | b, err := json.Marshal(msg) 17 | if err != nil { 18 | return "", err 19 | } 20 | return string(b) + DELIMITER, nil 21 | } 22 | 23 | // Returns random hex string 24 | func GetRandomHex(n int, allowedChars ...[]rune) string { 25 | var letters []rune 26 | if len(allowedChars) == 0 { 27 | letters = []rune("0123456789abcdef") 28 | } else { 29 | letters = allowedChars[0] 30 | } 31 | b := make([]rune, n) 32 | for i := range b { 33 | rand.Seed(time.Now().UTC().UnixNano() + int64(i<<20)) 34 | b[i] = letters[rand.Intn(len(letters))] 35 | } 36 | return string(b) 37 | } 38 | 39 | // Generate random IP between range 13.104.0.0/14 40 | func GetRandomIp() string { 41 | ip := fmt.Sprintf("13.%d.%d.%d", 104+rand.Intn(3), rand.Intn(255), rand.Intn(255)) 42 | return ip 43 | } 44 | 45 | func GetUuidV4() string { 46 | return uuid.NewV4().String() 47 | } 48 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/billikeu/Go-EdgeGPT 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/go-resty/resty/v2 v2.7.0 7 | github.com/gorilla/websocket v1.5.0 8 | github.com/satori/go.uuid v1.2.0 9 | github.com/tidwall/gjson v1.14.4 10 | ) 11 | 12 | require ( 13 | github.com/tidwall/match v1.1.1 // indirect 14 | github.com/tidwall/pretty v1.2.0 // indirect 15 | golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect 16 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect 17 | ) 18 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= 2 | github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= 3 | github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= 4 | github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 5 | github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= 6 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 7 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 8 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 9 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 10 | github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= 11 | github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= 12 | github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= 13 | github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= 14 | github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= 15 | github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= 16 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= 17 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= 18 | golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM= 19 | golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 20 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 21 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 22 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 23 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 24 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 25 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 26 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 27 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | 6 | "github.com/billikeu/Go-EdgeGPT/edgegpt" 7 | ) 8 | 9 | func callback(answer *edgegpt.Answer) { 10 | if answer.IsDone() { 11 | log.Println(answer.NumUserMessages(), answer.MaxNumUserMessages(), answer.Text()) 12 | } 13 | } 14 | 15 | func main() { 16 | log.SetFlags(log.LstdFlags | log.Lshortfile) 17 | bot := edgegpt.NewChatBot("cookie.json", []map[string]interface{}{}, "http://127.0.0.1:10809") 18 | err := bot.Init() 19 | if err != nil { 20 | panic(err) 21 | } 22 | err = bot.Ask("give me a joke", edgegpt.Creative, callback) 23 | if err != nil { 24 | panic(err) 25 | } 26 | err = bot.Ask("It's not funny", edgegpt.Creative, callback) 27 | if err != nil { 28 | panic(err) 29 | } 30 | } 31 | --------------------------------------------------------------------------------