(tools []dto.Tool, model string)
| 264 | } |
| 265 | |
| 266 | func 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 | |
| 287 | func CountTokenRealtime(info *relaycommon.RelayInfo, request dto.RealtimeEvent, model string) (int, int, error) { |
| 288 | audioToken := 0 |
no test coverage detected