(msgs []uctypes.GenAIMessage)
| 188 | } |
| 189 | |
| 190 | func getUsage(msgs []uctypes.GenAIMessage) uctypes.AIUsage { |
| 191 | var rtn uctypes.AIUsage |
| 192 | var found bool |
| 193 | for _, msg := range msgs { |
| 194 | if usage := msg.GetUsage(); usage != nil { |
| 195 | if !found { |
| 196 | rtn = *usage |
| 197 | found = true |
| 198 | } else { |
| 199 | rtn.InputTokens += usage.InputTokens |
| 200 | rtn.OutputTokens += usage.OutputTokens |
| 201 | rtn.NativeWebSearchCount += usage.NativeWebSearchCount |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | return rtn |
| 206 | } |
| 207 | |
| 208 | func GetChatUsage(chat *uctypes.AIChat) uctypes.AIUsage { |
| 209 | usage := getUsage(chat.NativeMessages) |
no test coverage detected