(info *relaycommon.RelayInfo, request dto.GeneralOpenAIRequest)
| 153 | } |
| 154 | |
| 155 | func CountTokenChatRequest(info *relaycommon.RelayInfo, request dto.GeneralOpenAIRequest) (int, error) { |
| 156 | tkm := 0 |
| 157 | msgTokens, err := CountTokenMessages(info, request.Messages, request.Model, request.Stream) |
| 158 | if err != nil { |
| 159 | return 0, err |
| 160 | } |
| 161 | tkm += msgTokens |
| 162 | if request.Tools != nil { |
| 163 | openaiTools := request.Tools |
| 164 | countStr := "" |
| 165 | for _, tool := range openaiTools { |
| 166 | countStr = tool.Function.Name |
| 167 | if tool.Function.Description != "" { |
| 168 | countStr += tool.Function.Description |
| 169 | } |
| 170 | if tool.Function.Parameters != nil { |
| 171 | countStr += fmt.Sprintf("%v", tool.Function.Parameters) |
| 172 | } |
| 173 | } |
| 174 | toolTokens := CountTokenInput(countStr, request.Model) |
| 175 | tkm += 8 |
| 176 | tkm += toolTokens |
| 177 | } |
| 178 | |
| 179 | return tkm, nil |
| 180 | } |
| 181 | |
| 182 | func CountTokenClaudeRequest(request dto.ClaudeRequest, model string) (int, error) { |
| 183 | tkm := 0 |
no test coverage detected