From 83e871f1ff687056bc574e2044c578a3e5912885 Mon Sep 17 00:00:00 2001 From: Howard Su Date: Thu, 27 Apr 2023 13:00:09 +0800 Subject: [PATCH] Fix Invalid Request using AzureOpenAI (#3522) This fixes the error when calling AzureOpenAI of gpt-35-turbo model. The error is: InvalidRequestError: logprobs, best_of and echo parameters are not available on gpt-35-turbo model. Please remove the parameter and try again. For more details, see https://go.microsoft.com/fwlink/?linkid=2227346. --- langchain/llms/openai.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/langchain/llms/openai.py b/langchain/llms/openai.py index bfcbea29..e8f85a76 100644 --- a/langchain/llms/openai.py +++ b/langchain/llms/openai.py @@ -242,10 +242,15 @@ class BaseOpenAI(BaseLLM): "frequency_penalty": self.frequency_penalty, "presence_penalty": self.presence_penalty, "n": self.n, - "best_of": self.best_of, "request_timeout": self.request_timeout, "logit_bias": self.logit_bias, } + + # Azure gpt-35-turbo doesn't support best_of + # don't specify best_of if it is 1 + if self.best_of > 1: + normal_params["best_of"] = self.best_of + return {**normal_params, **self.model_kwargs} def _generate(