includes tokenizer debug info on responses

This commit is contained in:
nai-degen
2023-06-02 01:59:12 -05:00
parent 4341dc5961
commit c8d74fe8fd
4 changed files with 21 additions and 3 deletions
+7 -1
View File
@@ -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);
};
+6 -2
View File
@@ -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,
+5
View File
@@ -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);
};
+3
View File
@@ -18,6 +18,9 @@ declare global {
onAborted?: () => void;
proceed: () => void;
heartbeatInterval?: NodeJS.Timeout;
promptTokens?: number;
// TODO: remove later
debug: Record<string, any>;
}
}
}