fixes issue with attempting to log non-completion endpoints

This commit is contained in:
nai-degen 2023-04-14 20:10:14 -07:00
parent 0f60fa9407
commit 34ed165a6f
1 changed files with 7 additions and 0 deletions

View File

@ -2,6 +2,8 @@ import { config } from "../../../config";
import { logQueue } from "../../../prompt-logging";
import { ProxyResHandlerWithBody } from ".";
const COMPLETE_ENDPOINT = "/v1/chat/completions";
/** If prompt logging is enabled, enqueues the prompt for logging. */
export const logPrompt: ProxyResHandlerWithBody = async (
_proxyRes,
@ -16,6 +18,11 @@ export const logPrompt: ProxyResHandlerWithBody = async (
throw new Error("Expected body to be an object");
}
// Only log prompts if we're making a request to a completion endpoint
if (!req.originalUrl.startsWith(COMPLETE_ENDPOINT)) {
return;
}
const model = req.body.model;
const promptFlattened = flattenMessages(req.body.messages);
const response = getResponseForModel({ model, body: responseBody });