-
Notifications
You must be signed in to change notification settings - Fork 64
/
message_file.go
89 lines (73 loc) · 2.14 KB
/
message_file.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
package proxy
import (
"encoding/json"
goopenai "github.com/sashabaranov/go-openai"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func logRetrieveMessageFileRequest(log *zap.Logger, prod bool, cid, tid, mid, fid string) {
if prod {
fields := []zapcore.Field{
zap.String(correlationId, cid),
zap.String("thread_id", tid),
zap.String("message_id", mid),
zap.String("file_id", fid),
}
log.Info("openai retrieve message file request", fields...)
}
}
func logRetrieveMessageFileResponse(log *zap.Logger, data []byte, prod bool, cid string) {
mf := &goopenai.MessageFile{}
err := json.Unmarshal(data, mf)
if err != nil {
logError(log, "error when unmarshalling message file response", prod, cid, err)
return
}
if prod {
fields := []zapcore.Field{
zap.String(correlationId, cid),
zap.String("id", mf.ID),
zap.String("object", mf.Object),
zap.Int("created_at", mf.CreatedAt),
zap.String("message_id", mf.MessageID),
}
log.Info("openai message file response", fields...)
}
}
func logListMessageFilesRequest(log *zap.Logger, prod bool, cid, tid, mid string, params map[string]string) {
if prod {
fields := []zapcore.Field{
zap.String(correlationId, cid),
zap.String("thread_id", tid),
zap.String("message_id", mid),
}
if v, ok := params["limit"]; ok {
fields = append(fields, zap.String("limit", v))
}
if v, ok := params["order"]; ok {
fields = append(fields, zap.String("order", v))
}
if v, ok := params["after"]; ok {
fields = append(fields, zap.String("after", v))
}
if v, ok := params["before"]; ok {
fields = append(fields, zap.String("before", v))
}
log.Info("openai list message files request", fields...)
}
}
func logListMessageFilesResponse(log *zap.Logger, data []byte, prod bool, cid string) {
files := &goopenai.MessageFilesList{}
err := json.Unmarshal(data, files)
if err != nil {
logError(log, "error when unmarshalling list message files response", prod, cid, err)
return
}
if prod {
fields := []zapcore.Field{
zap.String(correlationId, cid),
zap.Any("message_files", files.MessageFiles),
}
log.Info("openai list message files response", fields...)
}
}