-
Notifications
You must be signed in to change notification settings - Fork 57
/
completion.go
64 lines (53 loc) · 1.58 KB
/
completion.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
package proxy
import (
"encoding/json"
"github.com/bricks-cloud/bricksllm/internal/provider/anthropic"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func logCompletionRequest(log *zap.Logger, data []byte, prod, private bool, cid string) {
cr := &anthropic.CompletionRequest{}
err := json.Unmarshal(data, cr)
if err != nil {
logError(log, "error when unmarshalling anthropic completion request", prod, cid, err)
return
}
if prod {
fields := []zapcore.Field{
zap.String(correlationId, cid),
zap.String("model", cr.Model),
zap.Int("max_tokens_to_sample", cr.MaxTokensToSample),
zap.Any("stop_sequnces", cr.StopSequences),
zap.Float32("temperature", cr.Temperature),
zap.Int("top_p", cr.TopP),
zap.Int("top_k", cr.TopK),
zap.Bool("stream", cr.Stream),
}
if cr.Metadata != nil {
fields = append(fields, zap.Any("metadata", cr.Metadata))
}
if !private {
fields = append(fields, zap.String("prompt", cr.Prompt))
}
log.Info("anthropic completion request", fields...)
}
}
func logCompletionResponse(log *zap.Logger, data []byte, prod, private bool, cid string) {
cr := &anthropic.CompletionResponse{}
err := json.Unmarshal(data, cr)
if err != nil {
logError(log, "error when unmarshalling anthropic completion response", prod, cid, err)
return
}
if prod {
fields := []zapcore.Field{
zap.String(correlationId, cid),
zap.String("stop_reason", cr.StopReason),
zap.String("model", cr.Model),
}
if !private {
fields = append(fields, zap.String("completion", cr.Completion))
}
log.Info("anthropic completion response", fields...)
}
}