| 19 | } |
| 20 | |
| 21 | func ComputeCacheKeyForChatCompletionRequest(path string, req *goopenai.ChatCompletionRequest) string { |
| 22 | if req == nil { |
| 23 | return "" |
| 24 | } |
| 25 | |
| 26 | input := "" |
| 27 | for _, m := range req.Messages { |
| 28 | input += m.Name |
| 29 | input += m.Role |
| 30 | input += m.Content |
| 31 | } |
| 32 | |
| 33 | if req.ResponseFormat != nil && len(req.ResponseFormat.Type) != 0 { |
| 34 | return hasher.Hash(fmt.Sprintf("%s-%s-%s-%s", path, input, req.User, string(req.ResponseFormat.Type))) |
| 35 | } |
| 36 | |
| 37 | return hasher.Hash(fmt.Sprintf("%s-%s-%s", path, input, req.User)) |
| 38 | } |