Copy
---
title: Azure Cognitive Services Toolkit
---
이 toolkit은 `Azure Cognitive Services API`와 상호작용하여 일부 multimodal 기능을 구현하는 데 사용됩니다.
현재 이 toolkit에는 4개의 tool이 포함되어 있습니다:
- AzureCogsImageAnalysisTool: 이미지에서 caption, object, tag 및 text를 추출하는 데 사용됩니다. (참고: 이 tool은 `azure-ai-vision` package에 대한 의존성으로 인해 Mac OS에서는 아직 사용할 수 없으며, 현재 Windows와 Linux에서만 지원됩니다.)
- AzureCogsFormRecognizerTool: 문서에서 text, table 및 key-value pair를 추출하는 데 사용됩니다.
- AzureCogsSpeech2TextTool: 음성을 text로 변환하는 데 사용됩니다.
- AzureCogsText2SpeechTool: text를 음성으로 합성하는 데 사용됩니다.
- AzureCogsTextAnalyticsHealthTool: 의료 entity를 추출하는 데 사용됩니다.
먼저 Azure 계정을 설정하고 Cognitive Services resource를 생성해야 합니다. resource를 생성하려면 [여기](https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-apis-create-account?tabs=multiservice%2Cwindows)의 지침을 따르세요.
그런 다음 resource의 endpoint, key 및 region을 가져와서 환경 변수로 설정해야 합니다. 이들은 resource의 "Keys and Endpoint" 페이지에서 찾을 수 있습니다.
```python
pip install -qU azure-ai-formrecognizer > /dev/null
pip install -qU azure-cognitiveservices-speech > /dev/null
pip install -qU azure-ai-textanalytics > /dev/null
# For Windows/Linux
pip install -qU azure-ai-vision > /dev/null
Copy
pip install -qU langchain-community
Copy
import os
os.environ["OPENAI_API_KEY"] = "sk-"
os.environ["AZURE_COGS_KEY"] = ""
os.environ["AZURE_COGS_ENDPOINT"] = ""
os.environ["AZURE_COGS_REGION"] = ""
Toolkit 생성하기
Copy
from langchain_community.agent_toolkits import AzureCognitiveServicesToolkit
toolkit = AzureCognitiveServicesToolkit()
Copy
[tool.name for tool in toolkit.get_tools()]
Copy
['Azure Cognitive Services Image Analysis',
'Azure Cognitive Services Form Recognizer',
'Azure Cognitive Services Speech2Text',
'Azure Cognitive Services Text2Speech']
Agent 내에서 사용하기
Copy
from langchain.agents import AgentType, initialize_agent
from langchain_openai import OpenAI
Copy
llm = OpenAI(temperature=0)
agent = initialize_agent(
tools=toolkit.get_tools(),
llm=llm,
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
verbose=True,
)
Copy
agent.run(
"What can I make with these ingredients?"
"https://images.openai.com/blob/9ad5a2ab-041f-475f-ad6a-b51899c50182/ingredients.png"
)
Copy
> Entering new AgentExecutor chain...
Action:
\`\`\`
{
"action": "Azure Cognitive Services Image Analysis",
"action_input": "https://images.openai.com/blob/9ad5a2ab-041f-475f-ad6a-b51899c50182/ingredients.png"
}
\`\`\`
Observation: Caption: a group of eggs and flour in bowls
Objects: Egg, Egg, Food
Tags: dairy, ingredient, indoor, thickening agent, food, mixing bowl, powder, flour, egg, bowl
Thought: I can use the objects and tags to suggest recipes
Action:
\`\`\`
{
"action": "Final Answer",
"action_input": "You can make pancakes, omelettes, or quiches with these ingredients!"
}
\`\`\`
> Finished chain.
Copy
'You can make pancakes, omelettes, or quiches with these ingredients!'
Copy
audio_file = agent.run("Tell me a joke and read it out for me.")
Copy
> Entering new AgentExecutor chain...
Action:
\`\`\`
{
"action": "Azure Cognitive Services Text2Speech",
"action_input": "Why did the chicken cross the playground? To get to the other slide!"
}
\`\`\`
Observation: /tmp/tmpa3uu_j6b.wav
Thought: I have the audio file of the joke
Action:
\`\`\`
{
"action": "Final Answer",
"action_input": "/tmp/tmpa3uu_j6b.wav"
}
\`\`\`
> Finished chain.
Copy
'/tmp/tmpa3uu_j6b.wav'
Copy
from IPython import display
audio = display.Audio(audio_file)
display.display(audio)
Copy
agent.run(
"""The patient is a 54-year-old gentleman with a history of progressive angina over the past several months.
The patient had a cardiac catheterization in July of this year revealing total occlusion of the RCA and 50% left main disease ,
with a strong family history of coronary artery disease with a brother dying at the age of 52 from a myocardial infarction and
another brother who is status post coronary artery bypass grafting. The patient had a stress echocardiogram done on July , 2001 ,
which showed no wall motion abnormalities , but this was a difficult study due to body habitus. The patient went for six minutes with
minimal ST depressions in the anterior lateral leads , thought due to fatigue and wrist pain , his anginal equivalent. Due to the patient's
increased symptoms and family history and history left main disease with total occasional of his RCA was referred for revascularization with open heart surgery.
List all the diagnoses.
"""
)
Copy
> Entering new AgentExecutor chain...
Action:
\`\`\`
{
"action": "azure_cognitive_services_text_analyics_health",
"action_input": "The patient is a 54-year-old gentleman with a history of progressive angina over the past several months. The patient had a cardiac catheterization in July of this year revealing total occlusion of the RCA and 50% left main disease, with a strong family history of coronary artery disease with a brother dying at the age of 52 from a myocardial infarction and another brother who is status post coronary artery bypass grafting. The patient had a stress echocardiogram done on July, 2001, which showed no wall motion abnormalities, but this was a difficult study due to body habitus. The patient went for six minutes with minimal ST depressions in the anterior lateral leads, thought due to fatigue and wrist pain, his anginal equivalent. Due to the patient's increased symptoms and family history and history left main disease with total occasional of his RCA was referred for revascularization with open heart surgery."
}
\`\`\`
Observation: The text conatins the following healthcare entities: 54-year-old is a healthcare entity of type Age, gentleman is a healthcare entity of type Gender, progressive angina is a healthcare entity of type Diagnosis, past several months is a healthcare entity of type Time, cardiac catheterization is a healthcare entity of type ExaminationName, July of this year is a healthcare entity of type Time, total is a healthcare entity of type ConditionQualifier, occlusion is a healthcare entity of type SymptomOrSign, RCA is a healthcare entity of type BodyStructure, 50 is a healthcare entity of type MeasurementValue, % is a healthcare entity of type MeasurementUnit, left main is a healthcare entity of type BodyStructure, disease is a healthcare entity of type Diagnosis, family is a healthcare entity of type FamilyRelation, coronary artery disease is a healthcare entity of type Diagnosis, brother is a healthcare entity of type FamilyRelation, dying is a healthcare entity of type Diagnosis, 52 is a healthcare entity of type Age, myocardial infarction is a healthcare entity of type Diagnosis, brother is a healthcare entity of type FamilyRelation, coronary artery bypass grafting is a healthcare entity of type TreatmentName, stress echocardiogram is a healthcare entity of type ExaminationName, July, 2001 is a healthcare entity of type Time, wall motion abnormalities is a healthcare entity of type SymptomOrSign, body habitus is a healthcare entity of type SymptomOrSign, six minutes is a healthcare entity of type Time, minimal is a healthcare entity of type ConditionQualifier, ST depressions in the anterior lateral leads is a healthcare entity of type SymptomOrSign, fatigue is a healthcare entity of type SymptomOrSign, wrist pain is a healthcare entity of type SymptomOrSign, anginal equivalent is a healthcare entity of type SymptomOrSign, increased is a healthcare entity of type Course, symptoms is a healthcare entity of type SymptomOrSign, family is a healthcare entity of type FamilyRelation, left is a healthcare entity of type Direction, main is a healthcare entity of type BodyStructure, disease is a healthcare entity of type Diagnosis, occasional is a healthcare entity of type Course, RCA is a healthcare entity of type BodyStructure, revascularization is a healthcare entity of type TreatmentName, open heart surgery is a healthcare entity of type TreatmentName
Thought: I know what to respond
Action:
\`\`\`
{
"action": "Final Answer",
"action_input": "The text contains the following diagnoses: progressive angina, coronary artery disease, myocardial infarction, and coronary artery bypass grafting."
}
\`\`\`
> Finished chain.
Copy
'The text contains the following diagnoses: progressive angina, coronary artery disease, myocardial infarction, and coronary artery bypass grafting.'
Copy
---
<Callout icon="pen-to-square" iconType="regular">
[Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/azure_cognitive_services.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
[Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>