Skip to content

Commit

Permalink
-- add
Browse files Browse the repository at this point in the history
 - source attributions
  • Loading branch information
NoahAmethyst committed Jun 13, 2023
1 parent 8ab00f8 commit 8abcdf3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
25 changes: 19 additions & 6 deletions bing.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ func (b *BingChatHub) initWsConnect() error {
}

type MsgResp struct {
Suggest []string
Notify chan string
Title string
Suggest []string
Notify chan string
Title string
References map[string]string
}

// SendMessage send message to bing chat and return a response with message(string) channel
Expand Down Expand Up @@ -258,18 +259,28 @@ func (b *BingChatHub) SendMessage(msg string) (*MsgResp, error) {
if !startRev {
continue
}

//response continue
if resp.Type == 1 && len(resp.Arguments) > 0 && len(resp.Arguments[0].Messages) > 0 {
if resp.Arguments[0].Messages[0].SuggestedResponses != nil {
var suggests []string

if len(resp.Arguments[0].Messages[0].SuggestedResponses) > 0 {
suggests := make([]string, 0, len(resp.Arguments[0].Messages[0].SuggestedResponses))
for _, suggest := range resp.Arguments[0].Messages[0].SuggestedResponses {
suggests = append(suggests, suggest.Text)
}
msgRespChannel.Suggest = suggests
}

if len(resp.Arguments[0].Messages[0].SourceAttributions) > 0 {
references := make(map[string]string)
for _, source := range resp.Arguments[0].Messages[0].SourceAttributions {
references[source.ProviderDisplayName] = source.SeeMoreUrl
}
msgRespChannel.References = references
}

if resp.Arguments[0].Messages[0].MessageType == "Disengaged" {
b.Reset()

break
}
msg := strings.TrimSpace(resp.Arguments[0].Messages[0].Text)
Expand All @@ -283,6 +294,8 @@ func (b *BingChatHub) SendMessage(msg string) (*MsgResp, error) {
msgRespChannel.Notify <- msg[len(lastMsg):]
lastMsg = msg
}

//response done
if resp.Type == 2 {
break
}
Expand Down
8 changes: 7 additions & 1 deletion model.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type MessageResp struct {
Size string `json:"size"`
} `json:"body"`
} `json:"adaptiveCards"`
SourceAttributions []interface{} `json:"sourceAttributions"`
SourceAttributions []SourceAttribution `json:"sourceAttributions"`
Feedback struct {
Tag interface{} `json:"tag"`
UpdatedOn interface{} `json:"updatedOn"`
Expand Down Expand Up @@ -133,3 +133,9 @@ type MessageResp struct {
RequestId string `json:"requestId"`
} `json:"arguments"`
}

type SourceAttribution struct {
ProviderDisplayName string `json:"providerDisplayName"`
SeeMoreUrl string `json:"seeMoreUrl"`
SearchQuery string `json:"searchQuery"`
}

0 comments on commit 8abcdf3

Please sign in to comment.