MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / CountTokenClaudeTools

Function CountTokenClaudeTools

service/token_counter.go:266–285  ·  view source on GitHub ↗
(tools []dto.Tool, model string)

Source from the content-addressed store, hash-verified

264}
265
266func CountTokenClaudeTools(tools []dto.Tool, model string) (int, error) {
267 tokenEncoder := getTokenEncoder(model)
268 tokenNum := 0
269
270 for _, tool := range tools {
271 tokenNum += getTokenNum(tokenEncoder, tool.Name)
272 tokenNum += getTokenNum(tokenEncoder, tool.Description)
273
274 schemaJSON, err := json.Marshal(tool.InputSchema)
275 if err != nil {
276 return 0, errors.New(fmt.Sprintf("marshal_tool_schema_fail: %s", err.Error()))
277 }
278 tokenNum += getTokenNum(tokenEncoder, string(schemaJSON))
279 }
280
281 // Add a constant for tool formatting (this may need adjustment based on Claude's exact formatting)
282 tokenNum += len(tools) * 3 // Assuming 3 tokens per tool for formatting
283
284 return tokenNum, nil
285}
286
287func CountTokenRealtime(info *relaycommon.RelayInfo, request dto.RealtimeEvent, model string) (int, int, error) {
288 audioToken := 0

Callers 1

CountTokenClaudeRequestFunction · 0.85

Calls 3

getTokenEncoderFunction · 0.85
getTokenNumFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected