-
Notifications
You must be signed in to change notification settings - Fork 64
/
models.go
91 lines (75 loc) · 1.98 KB
/
models.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
package proxy
import (
"encoding/json"
goopenai "github.com/sashabaranov/go-openai"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func logListModelsResponse(log *zap.Logger, data []byte, prod bool) {
models := &goopenai.ModelsList{}
err := json.Unmarshal(data, models)
if err != nil {
logError(log, "error when unmarshalling list models response", prod, err)
return
}
if prod {
fields := []zapcore.Field{
zap.Any("models", models.Models),
}
log.Info("openai list models response", fields...)
}
}
func logRetrieveModelRequest(log *zap.Logger, prod bool, model string) {
if prod {
fields := []zapcore.Field{
zap.String("model", model),
}
log.Info("openai retrieve model resquest", fields...)
}
}
func logRetrieveModelResponse(log *zap.Logger, data []byte, prod bool) {
model := &goopenai.Model{}
err := json.Unmarshal(data, model)
if err != nil {
logError(log, "error when unmarshalling retrieve model response", prod, err)
return
}
if prod {
fields := []zapcore.Field{
zap.String("id", model.ID),
zap.Int64("created", model.CreatedAt),
zap.String("object", model.Object),
zap.String("owned_by", model.OwnedBy),
}
log.Info("openai retrieve model response", fields...)
}
}
func logDeleteModelRequest(log *zap.Logger, prod bool, model string) {
if prod {
fields := []zapcore.Field{
zap.String("model", model),
}
log.Info("openai delete model resquest", fields...)
}
}
type DeletionResponse struct {
Id string `json:"id"`
Object string `json:"object"`
Deleted bool `json:"deleted"`
}
func logDeleteModelResponse(log *zap.Logger, data []byte, prod bool) {
resp := &DeletionResponse{}
err := json.Unmarshal(data, resp)
if err != nil {
logError(log, "error when unmarshalling model deletion response", prod, err)
return
}
if prod {
fields := []zapcore.Field{
zap.String("id", resp.Id),
zap.String("object", resp.Object),
zap.Bool("deleted", resp.Deleted),
}
log.Info("openai delete model response", fields...)
}
}