handles Azure deviation from OpenAI spec on logprobs param

This commit is contained in:
nai-degen 2024-01-24 16:01:19 -06:00
parent ad465be363
commit 4a4b60ebcd
2 changed files with 13 additions and 0 deletions

View File

@ -18,6 +18,16 @@ export const addAzureKey: RequestPreprocessor = (req) => {
req.key = keyPool.get(model);
req.body.model = model;
// Handles the sole Azure API deviation from the OpenAI spec (that I know of)
if (req.body.logrpobs || req.body.top_logprobs) {
// OpenAI wants logprobs: true/false and top_logprobs: number
// Azure seems to just want to combine them into logprobs: number
if (typeof req.body.logprobs === "boolean") {
req.body.logprobs = req.body.top_logprobs || undefined;
delete req.body.top_logprobs
}
}
req.log.info(
{ key: req.key.hash, model },

View File

@ -87,6 +87,9 @@ export const OpenAIV1ChatCompletionSchema = z
logit_bias: z.any().optional(),
user: z.string().max(500).optional(),
seed: z.number().int().optional(),
// Be warned that Azure OpenAI combines these two into a single field.
// It's the only deviation from the OpenAI API that I'm aware of so I have
// special cased it in `addAzureKey` rather than expecting clients to do it.
logprobs: z.boolean().optional().default(false),
top_logprobs: z.number().int().optional(),
})