-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.go
132 lines (110 loc) · 3.4 KB
/
message.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package minimax
import (
"context"
"net/http"
)
type ListMessageOption struct {
ThreadId string `json:"thread_id"`
Limit int64 `json:"limit,omitempty"`
Order string `json:"order,omitempty"`
After string `json:"after,omitempty"`
Before string `json:"before,omitempty"`
}
type AsstMessage struct {
ID string `json:"id"`
Object string `json:"object"`
CreatedAt int64 `json:"created_at"`
ThreadId string `json:"thread_id"`
Role string `json:"role"`
Content []*Content `json:"content"`
FileIds []string `json:"file_ids"`
AssistantId string `json:"assistant_id"`
RunId string `json:"run_id"`
MetaData map[string]string `json:"metadata"`
}
type Content struct {
Typ string `json:"type"`
Text *TextContent `json:"text"`
ImageFile *ImageFile `json:"image_file"`
}
type TextContent struct {
Value string `json:"value"`
Annotations []*Annotation `json:"annotations"`
}
type ImageFile struct {
FileId string `json:"file_id"`
}
type Annotation struct {
Typ string `json:"type"`
Text string `json:"text"`
StartIndex int64 `json:"start_index"`
EndIndex int64 `json:"end_index"`
FileCitation *FileCitation `json:"file_citation"`
WebCitation *WebCitation `json:"web_citation"`
}
type FileCitation struct {
FileId string `json:"file_id"`
Quote string `json:"quote"`
}
type WebCitation struct {
Url string `json:"url"`
Quote string `json:"quote"`
}
type ListMessagesResponse struct {
Object string `json:"object"`
Data []*AsstMessage `json:"data"`
FirstId string `json:"first_id"`
LastId string `json:"last_id"`
BaseResp *BaseResp `json:"base_resp"`
}
type MessageCreateRequest struct {
ThreadId string `json:"thread_id"`
Role string `json:"role"`
Content string `json:"content"`
FileIds []string `json:"file_ids,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
type MessageResponse struct {
*AsstMessage
BaseResp *BaseResp `json:"base_resp"`
}
type MessageRetrieveRequest struct {
MessageId string `json:"message_id"`
ThreadId string `json:"thread_id"`
}
func (c *Client) ListMessages(ctx context.Context, request *ListMessageOption) (*ListMessagesResponse, error) {
req, err := c.newRequest(ctx, c.queryBuilder.Build(c.fullURL("/threads/messages/list"), request), http.MethodGet)
if err != nil {
return nil, err
}
resp := &ListMessagesResponse{}
err = c.send(req, resp)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *Client) CreateMessages(ctx context.Context, request *MessageCreateRequest) (*MessageResponse, error) {
req, err := c.newRequest(ctx, c.fullURL("/threads/messages/add"), http.MethodPost, withBody(request))
if err != nil {
return nil, err
}
resp := &MessageResponse{}
err = c.send(req, resp)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *Client) RetrieveMessages(ctx context.Context, request *MessageRetrieveRequest) (*MessageResponse, error) {
req, err := c.newRequest(ctx, c.queryBuilder.Build(c.fullURL("/threads/messages/retrieve"), request), http.MethodGet)
if err != nil {
return nil, err
}
resp := &MessageResponse{}
err = c.send(req, resp)
if err != nil {
return nil, err
}
return resp, nil
}