Start using Langchain with Azure OpenAI gpt-35-turbo with this fix

I have hit a couple of issues trying to get Langchain with Azure OpenAI and completions API using gtp-35-turbo model.
First, it is not clear in OpenAI documentation as to which parameters to use while trying to call AzureOpenAI endpoints…
The “deployment_name” should be the model deployment name under your deployments under each custom AzureOpenAI domain name…
The model name is the OpenAI model name you have deployed e.g. gpt-35-turbo…

Once these are configured in theory you are ready to start using the API’s…
However while gpt-35-turbo model, I got an error message…“langchain: logprobs, best_of and echo parameters are not available on gpt-35-turbo model”.
Error is documented under landchain github repo here. The only way I found to fix this is creating a new class and nullifying these parameters the error message complains about as below.
import os
from langchain.llms import AzureOpenAI
os.environ["OPENAI_API_TYPE"] = 'azure'
os.environ["OPENAI_API_VERSION"]='2022-12-01'
os.environ["OPENAI_API_BASE"]='XXX'
os.environ["OPENAI_API_KEY"] ='XXX'
class NewAzureOpenAI(AzureOpenAI):
stop: list[str] = None
@property
def _invocation_params(self):
params = super()._invocation_params
# fix InvalidRequestError: logprobs, best_of and echo parameters are not available on gpt-35-turbo model.
params.pop('logprobs', None)
params.pop('best_of', None)
params.pop('echo', None)
#params['stop'] = self.stop
return params
llm = NewAzureOpenAI(deployment_name="gpt35-turbo-ozguler", model_name="gpt-35-turbo")
print(llm("Tell me a joke"))
print(llm)

Hope this helps anyone trying to start using Langchain with OpenAI…