-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bing-creative, bing-balanced, bing-precise model (unstable)
- Loading branch information
1 parent
c9aa30b
commit ce503ef
Showing
7 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package bing | ||
|
||
import ( | ||
"chat/globals" | ||
"chat/utils" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type ChatProps struct { | ||
Message []globals.Message | ||
Model string | ||
} | ||
|
||
func (c *ChatInstance) CreateStreamChatRequest(props *ChatProps, hook globals.Hook) error { | ||
var conn *utils.WebSocket | ||
if conn = utils.NewWebsocketClient(c.GetEndpoint()); conn == nil { | ||
return fmt.Errorf("sparkdesk error: websocket connection failed") | ||
} | ||
defer conn.DeferClose() | ||
|
||
model, _ := strings.CutPrefix(props.Model, "bing-") | ||
if err := conn.SendJSON(&ChatRequest{ | ||
Prompt: props.Message[len(props.Message)-1].Content, | ||
Cookies: c.Cookies, | ||
Model: model, | ||
}); err != nil { | ||
return err | ||
} | ||
|
||
for { | ||
form := utils.ReadForm[ChatResponse](conn) | ||
if form == nil { | ||
return nil | ||
} | ||
|
||
if form.Error != "" && form.End { | ||
return fmt.Errorf("bing error: %s", form.Error) | ||
} | ||
|
||
if err := hook(form.Response); err != nil { | ||
return err | ||
} | ||
|
||
if len(form.Suggested) > 0 { | ||
message := "" | ||
for _, suggested := range form.Suggested { | ||
message += fmt.Sprintf("- %s\n", suggested) | ||
} | ||
|
||
if err := hook(fmt.Sprintf("\n\n%s", message)); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
package bing | ||
|
||
import ( | ||
"chat/globals" | ||
"chat/utils" | ||
"fmt" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type ChatInstance struct { | ||
Endpoint string | ||
Cookies map[string]string | ||
Cookies *map[string]interface{} | ||
} | ||
|
||
type ChatProps struct { | ||
Message []globals.Message | ||
func (c *ChatInstance) GetEndpoint() string { | ||
return fmt.Sprintf("%s/chat", c.Endpoint) | ||
} | ||
|
||
func NewChatInstance(endpoint, cookies string) *ChatInstance { | ||
form := utils.UnmarshalForm[map[string]interface{}](cookies) | ||
return &ChatInstance{ | ||
Endpoint: endpoint, | ||
Cookies: form, | ||
} | ||
} | ||
|
||
func NewChatInstanceFromConfig() *ChatInstance { | ||
return NewChatInstance(viper.GetString("bing.endpoint"), viper.GetString("bing.cookies")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package bing | ||
|
||
// see https://github.com/Deeptrain-Community/chatnio-bing-service | ||
|
||
type ChatRequest struct { | ||
Prompt string `json:"prompt"` | ||
Cookies *map[string]interface{} `json:"cookies"` | ||
Model string `json:"model"` | ||
} | ||
|
||
type ChatResponse struct { | ||
Response string `json:"response"` | ||
Suggested []string `json:"suggested"` | ||
Error string `json:"error"` | ||
End bool `json:"end"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters