mirror of
https://github.com/musistudio/claude-code-router.git
synced 2026-01-30 06:12:06 +00:00
add count_tokens api
This commit is contained in:
@@ -5,10 +5,17 @@ import { join } from "path";
|
||||
import fastifyStatic from "@fastify/static";
|
||||
import { readdirSync, statSync, readFileSync, writeFileSync, existsSync } from "fs";
|
||||
import { homedir } from "os";
|
||||
import {calculateTokenCount} from "./utils/router";
|
||||
|
||||
export const createServer = (config: any): Server => {
|
||||
const server = new Server(config);
|
||||
|
||||
server.app.post("/v1/messages/count_tokens", async (req, reply) => {
|
||||
const {messages, tools, system} = req.body;
|
||||
const tokenCount = calculateTokenCount(messages, system, tools);
|
||||
return { "input_tokens": tokenCount }
|
||||
});
|
||||
|
||||
// Add endpoint to read config.json with access control
|
||||
server.app.get("/api/config", async (req, reply) => {
|
||||
return await readConfigFile();
|
||||
|
||||
@@ -9,7 +9,7 @@ import { readFile } from 'fs/promises'
|
||||
|
||||
const enc = get_encoding("cl100k_base");
|
||||
|
||||
const calculateTokenCount = (
|
||||
export const calculateTokenCount = (
|
||||
messages: MessageParam[],
|
||||
system: any,
|
||||
tools: Tool[]
|
||||
|
||||
Reference in New Issue
Block a user