forked from cherish-chat/chatgpt-firefox
/
types.go
50 lines (46 loc) · 1.25 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package chatgpt
import (
"encoding/json"
"strings"
)
type ConversationStreamResponseItem struct {
Message struct {
Id string `json:"id"`
Author struct {
Role string `json:"role"`
Name interface{} `json:"name"`
Metadata struct {
} `json:"metadata"`
} `json:"author"`
CreateTime interface{} `json:"create_time"`
UpdateTime interface{} `json:"update_time"`
Content struct {
ContentType string `json:"content_type"`
Parts []string `json:"parts"`
} `json:"content"`
EndTurn bool `json:"end_turn"`
Weight float64 `json:"weight"`
Metadata struct {
MessageType string `json:"message_type"`
ModelSlug string `json:"model_slug"`
FinishDetails struct {
Type string `json:"type"`
Stop string `json:"stop"`
} `json:"finish_details"`
} `json:"metadata"`
Recipient string `json:"recipient"`
} `json:"message"`
ConversationId string `json:"conversation_id"`
Error interface{} `json:"error"`
}
func (i *ConversationStreamResponseItem) String() string {
bytes, err := json.Marshal(i)
if err != nil {
return ""
}
return string(bytes)
}
func (i *ConversationStreamResponseItem) Text() string {
parts := i.Message.Content.Parts
return strings.Join(parts, "\n")
}