Hi,
I’m unable to access Azure OpenAI from CrewAI agents.
This is my python notebook code. Can someone please check this and help me fix this?
os.environ["AZURE_OPENAI_API_KEY"] = <KEY1>
os.environ["AZURE_OPENAI_ENDPOINT"] = <Endpoint URL>
##Agents
extract_cli_marker = Agent(
role="Senior Medical Researcher",
goal="Identify and analyze clinical markers for heart failure in provided data",
verbose=True,
memory=True,
backstory=(
"With a strong background in cardiology and clinical research, "
"you specialize in identifying key biomarkers and diagnostic criteria "
"for heart failure. Your expertise allows you to analyze complex clinical data "
"and provide actionable insights for diagnosis and treatment."
),
tools=[ScrapeWebsiteTool()],
llm="azure/gpt-4o",
allow_delegation=True
)
identify_hf = Agent(
role="Cardiology Specialist",
goal=f"Determine if a patient has heart failure based on upon the given medical documents.",
verbose=True,
memory=True,
backstory=(
"""As a cardiology specialist, you have extensive experience in diagnosing heart failure
using clinical data, lab results, and imaging studies. Your expertise ensures accurate
and timely diagnosis for patients.
"""
),
llm="azure/gpt-4o",
allow_delegation=False
)
##tasks
task_extract_cli_marker = Task(
description=(
"Analyze the provided clinical data to identify key markers for heart failure using the top validated websites at internet and with your own knowledge. Combine them come up with a consildate marker"
"Focus on identifying relevant biomarkers, symptoms, and diagnostic criteria. "
"Your final report should clearly articulate the clinical markers, "
"their significance, and how they contribute to the diagnosis of heart failure."
),
expected_output=(
"A detailed report identifying the clinical markers for heart failure, "
"including biomarkers, symptoms, and diagnostic criteria. "
"The report should be 3 paragraphs long and provide a clear explanation "
"of the significance of each marker."
),
agent=extract_cli_marker,
)
task_identify_hf = Task(
description=(
f"Analyze the medical documents of the given patient to determine if they have heart failure. Medical document : {subject_notes}"
"Use tools to retrieve the patient's medical records, including lab results, imaging reports, and clinical notes. "
"Focus on identifying key markers such as elevated BNP/NT-proBNP levels, reduced ejection fraction (LVEF < 40%), "
"and symptoms like shortness of breath, fatigue, or peripheral edema. "
"Provide a clear yes/no answer and a line of evidence supporting the diagnosis."
),
expected_output=(
"A concise answer (yes/no) indicating whether the patient has heart failure, "
"followed by a line of evidence supporting the diagnosis. "
"For example: 'Yes, the patient has heart failure due to an elevated BNP level of 800 pg/mL.'"
),
agent=identify_hf
)
crew=Crew(
agents=[extract_cli_marker, identify_hf],
tasks=[task_extract_cli_marker, task_identify_hf],
process=Process.sequential,
)
result=crew.kickoff(inputs={'topic':'Identify if the patient has Heart Failure'})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File c:\Users\userID\AppData\Local\anaconda3\envs\crewai\lib\site-packages\litellm\llms\azure\azure.py:353, in AzureChatCompletion.completion(self, model, messages, model_response, api_key, api_base, api_version, api_type, azure_ad_token, dynamic_params, print_verbose, timeout, logging_obj, optional_params, litellm_params, logger_fn, acompletion, headers, client)
351 ### CHECK IF CLOUDFLARE AI GATEWAY ###
352 ### if so - set the model as part of the base url
--> 353 if "gateway.ai.cloudflare.com" in api_base:
354 ## build base url - assume api base includes resource name
355 if client is None:
TypeError: argument of type 'NoneType' is not iterable
During handling of the above exception, another exception occurred:
AzureOpenAIError Traceback (most recent call last)
File c:\Users\userID\AppData\Local\anaconda3\envs\crewai\lib\site-packages\litellm\main.py:1185, in completion(model, messages, timeout, temperature, top_p, n, stream, stream_options, stop, max_completion_tokens, max_tokens, modalities, prediction, audio, presence_penalty, frequency_penalty, logit_bias, user, response_format, seed, tools, tool_choice, logprobs, top_logprobs, parallel_tool_calls, deployment_id, extra_headers, functions, function_call, base_url, api_version, api_key, model_list, **kwargs)
1184 ## COMPLETION CALL
-> 1185 response = azure_chat_completions.completion(
1186 model=model,
1187 messages=messages,
1188 headers=headers,
1189 api_key=api_key,
1190 api_base=api_base,
1191 api_version=api_version,
1192 api_type=api_type,
1193 dynamic_params=dynamic_params,
...
(...)
2045 request=httpx.Request(method="POST", url="https://openai.com/"),
2046 )
APIError: litellm.APIError: AzureException APIError - argument of type 'NoneType' is not iterable