-
Notifications
You must be signed in to change notification settings - Fork 64
/
util.go
42 lines (34 loc) · 845 Bytes
/
util.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
package route
import (
"fmt"
goopenai "github.com/sashabaranov/go-openai"
)
func ComputeCacheKeyForEmbeddingsRequest(path string, req *goopenai.EmbeddingRequest) string {
if req == nil {
return ""
}
input := ""
if arr, ok := req.Input.([]interface{}); ok {
for _, ele := range arr {
converted, ok := ele.(string)
if ok {
input += converted
}
}
} else if ele, ok := req.Input.(string); ok {
input += ele
}
return fmt.Sprintf("%s-%s-%s-%s", path, input, req.EncodingFormat, req.User)
}
func ComputeCacheKeyForChatCompletionRequest(path string, req *goopenai.ChatCompletionRequest) string {
if req == nil {
return ""
}
input := ""
for _, m := range req.Messages {
input += m.Name
input += m.Role
input += m.Content
}
return fmt.Sprintf("%s-%s-%s-%s", path, input, req.User, req.ResponseFormat)
}