Find answers from the community

Updated last year

AzureOpenAI

Hi Guys...I am using Azure OpenAI in the below code and getting error message "InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.chat_completion.ChatCompletion'>".
Below is the code- llm = AzureOpenAI(
model="gpt-35-turbo",
model_name="text-davinci-003",
deployment_id=os.getenv("OPENAI_API_DEPLOYMENT_NAME"),
api_key=os.getenv("OPENAI_API_KEY"),
api_base=os.getenv("OPENAI_API_BASED"),
api_type=os.getenv("OPENAI_API_TYPE"),
api_version=os.getenv("OPENAI_API_VERSION"),
)

service_context = ServiceContext.from_defaults(
llm=llm,
)
set_global_service_context(service_context)

node_parser = SimpleNodeParser.from_defaults(
text_splitter=text_splitter,
metadata_extractor=metadata_extractor
)


ls_spilt_document=[]
for document_page in doc_patient_visit:
ls_spilt_document=markdown_splitter.split_text(document_page.page_content)
for split_index in range(len(ls_spilt_document)):
if "Patient Demographics" in list(ls_spilt_document[split_index].metadata.keys()):
document = Document(text=ls_spilt_document[split_index].page_content)
nodes = node_parser.get_nodes_from_documents([document],show_progress=True)"
W
G
L
21 comments
It uses engine while defining Azure llm. Could you try with that once
Thanks for your response.Yes this works with this line of code 'llm.complete("what is life")'. However it fails at the line "nodes = node_parser.get_nodes_from_documents([document])"
detailed error message "/usr/local/lib/python3.10/dist-packages/openai/api_resources/abstract/engine_api_resource.py in __prepare_create_request(cls, api_key, api_base, api_type, api_version, organization, **params)
83 if typed_api_type in (util.ApiType.AZURE, util.ApiType.AZURE_AD):
84 if deployment_id is None and engine is None:
---> 85 raise error.InvalidRequestError(
86 "Must provide an 'engine' or 'deployment_id' parameter to create a %s"
87 % cls,

InvalidRequestError: Must provide an 'engine' or 'deployment_id' parameter to create a <class 'openai.api_resources.chat_completion.ChatCompletion'>"
Can you show how you are importing AzureOpenAI, is it via llamaindex or langchain?
Yea, double check you followed that example
setting the global service context solves a lot of issues
I am importing AzureOpenAI via llamaindex. from llama_index.llms import OpenAI,AzureOpenAI
Yes that was my understanding as well. In spite of setting Global context, I am getting error...maybe I am missing something here..Here is the code from llama_index.llms import AzureOpenAI llm=AzureOpenAI(
model="gpt-35-turbo",
model_name="text-davinci-003",
deployment_id=os.getenv("OPENAI_API_DEPLOYMENT_NAME"),
api_key=os.getenv("OPENAI_API_KEY"),
api_base=os.getenv("OPENAI_API_BASED"),
api_type=os.getenv("OPENAI_API_TYPE"),
api_version=os.getenv("OPENAI_API_VERSION"),
)

service_context = ServiceContext.from_defaults(
llm=llm,
)
set_global_service_context(service_context)
Just tried with AzureOpenAI with the following code
Plain Text
import openai
openai.api_key = AZURE_API_KEY
openai.api_base = AZURE_API_BASE_URL
openai.api_type = API_TYPE
openai.api_version = API_VERSION
llm = AzureOpenAI(engine="engine_name", model="gpt-35-turbo", temperature=0.0)
I am using MarvinMetadataExtractor, do I have to explicitly pass the Azure OpenAI parameters
this is the code " @ai_model
class PatientDemographic(BaseModel):
Address:str=Field(...,description="Address of the patient")
Contact_number:str=Field(...,description="Contact number at work,home and office")
contact_email:str=Field(...,description="Email id of the patient")
Language:str=Field(...,description="Language of the patient")
Race:str=Field(...,description="Race or Ethinicity of the patient")"
Attachment
image.png
I had tried this earlier...still getting the same error. Not sure if this is related to Marvin
You have set OpenAI key for Marvin?
marvin.settings.openai.api_key = os.environ["OPENAI_API_KEY"]
Yes tried that as well
marvin.settings.azure_openai.api_key=os.environ['OPENAI_API_KEY']
marvin.settings.azure_openai.api_base=os.environ['OPENAI_API_BASE']
marvin.settings.azure_openai.deployment_name=os.environ['OPENAI_API_DEPLOYMENT_NAME']
marvin.settings.azure_openai.api_type='azure'
marvin.settings.llm_model = 'azure_openai/gpt-3.5-turbo'

marvin.settings.azure_openai.api_version=os.environ['OPENAI_API_VERSION']
I'm not sure if marvin is compatible with azure tbh
Thanks for your inputs
Add a reply
Sign up and join the conversation on Discord