includes tokenizer debug info on responses
This commit is contained in:
@@ -108,10 +108,16 @@ const anthropicResponseHandler: ProxyResHandlerWithBody = async (
|
||||
body.proxy_note = `Prompts are logged on this proxy instance. See ${host} for more information.`;
|
||||
}
|
||||
|
||||
if (!req.originalUrl.includes("/v1/complete") && !req.originalUrl.includes("/complete")) {
|
||||
if (req.inboundApi === "openai") {
|
||||
req.log.info("Transforming Anthropic response to OpenAI format");
|
||||
body = transformAnthropicResponse(body);
|
||||
}
|
||||
|
||||
// TODO: Remove once tokenization is stable
|
||||
if (req.debug) {
|
||||
body.proxy_tokenizer_debug_info = req.debug;
|
||||
}
|
||||
|
||||
res.status(200).json(body);
|
||||
};
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ export function writeErrorResponse(
|
||||
res.write(`data: [DONE]\n\n`);
|
||||
res.end();
|
||||
} else {
|
||||
if (req.debug) {
|
||||
errorPayload.error.proxy_tokenizer_debug_info = req.debug;
|
||||
}
|
||||
res.status(statusCode).json(errorPayload);
|
||||
}
|
||||
}
|
||||
@@ -57,7 +60,8 @@ export const handleProxyError: httpProxy.ErrorCallback = (err, req, res) => {
|
||||
export const handleInternalError = (
|
||||
err: Error,
|
||||
req: Request,
|
||||
res: Response
|
||||
res: Response,
|
||||
errorType: string = "proxy_internal_error"
|
||||
) => {
|
||||
try {
|
||||
const isZod = err instanceof ZodError;
|
||||
@@ -86,7 +90,7 @@ export const handleInternalError = (
|
||||
} else {
|
||||
writeErrorResponse(req, res, 500, {
|
||||
error: {
|
||||
type: "proxy_rewriter_error",
|
||||
type: errorType,
|
||||
proxy_note: `Reverse proxy encountered an error before it could reach the upstream API.`,
|
||||
message: err.message,
|
||||
stack: err.stack,
|
||||
|
||||
@@ -125,6 +125,11 @@ const openaiResponseHandler: ProxyResHandlerWithBody = async (
|
||||
body.proxy_note = `Prompts are logged on this proxy instance. See ${host} for more information.`;
|
||||
}
|
||||
|
||||
// TODO: Remove once tokenization is stable
|
||||
if (req.debug) {
|
||||
body.proxy_tokenizer_debug_info = req.debug;
|
||||
}
|
||||
|
||||
res.status(200).json(body);
|
||||
};
|
||||
|
||||
|
||||
Vendored
+3
@@ -18,6 +18,9 @@ declare global {
|
||||
onAborted?: () => void;
|
||||
proceed: () => void;
|
||||
heartbeatInterval?: NodeJS.Timeout;
|
||||
promptTokens?: number;
|
||||
// TODO: remove later
|
||||
debug: Record<string, any>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user