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

Ozgur Guler
2 min readMay 5, 2023

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)
Adding a picture of the code too as on sadari the code call does not seem to be visible

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

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response