Microsoft 365는이 노트북은 LangChain을Microsoft가 소유한 생산성 소프트웨어, 협업 및 클라우드 기반 서비스의 제품군입니다. 참고:Office 365는Microsoft 365로 브랜드가 변경되었습니다.
Office365 이메일 및 캘린더에 연결하는 방법을 안내합니다.
이 toolkit을 사용하려면 Microsoft Graph 인증 및 권한 부여 개요에 설명된 자격 증명을 설정해야 합니다. CLIENT_ID와 CLIENT_SECRET을 받은 후 아래에 환경 변수로 입력할 수 있습니다.
여기의 인증 지침을 사용할 수도 있습니다.
Copy
pip install -qU O365
pip install -qU beautifulsoup4 # This is optional but is useful for parsing HTML messages
pip install -qU langchain-community
환경 변수 할당
toolkit은 사용자를 인증하기 위해CLIENT_ID 및 CLIENT_SECRET 환경 변수를 읽으므로 여기에서 설정해야 합니다. 나중에 agent를 사용하려면 OPENAI_API_KEY도 설정해야 합니다.
Copy
# Set environmental variables here
Toolkit 생성 및 Tool 가져오기
시작하려면 toolkit을 생성해야 나중에 해당 tool에 액세스할 수 있습니다.Copy
from langchain_community.agent_toolkits import O365Toolkit
toolkit = O365Toolkit()
tools = toolkit.get_tools()
tools
Copy
[O365SearchEvents(name='events_search', description=" Use this tool to search for the user's calendar events. The input must be the start and end datetimes for the search query. The output is a JSON list of all the events in the user's calendar between the start and end times. You can assume that the user can not schedule any meeting over existing meetings, and that the user is busy during meetings. Any times without events are free for the user. ", args_schema=<class 'langchain_community.tools.office365.events_search.SearchEventsInput'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, handle_tool_error=False, account=Account Client Id: f32a022c-3c4c-4d10-a9d8-f6a9a9055302),
O365CreateDraftMessage(name='create_email_draft', description='Use this tool to create a draft email with the provided message fields.', args_schema=<class 'langchain_community.tools.office365.create_draft_message.CreateDraftMessageSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, handle_tool_error=False, account=Account Client Id: f32a022c-3c4c-4d10-a9d8-f6a9a9055302),
O365SearchEmails(name='messages_search', description='Use this tool to search for email messages. The input must be a valid Microsoft Graph v1.0 $search query. The output is a JSON list of the requested resource.', args_schema=<class 'langchain_community.tools.office365.messages_search.SearchEmailsInput'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, handle_tool_error=False, account=Account Client Id: f32a022c-3c4c-4d10-a9d8-f6a9a9055302),
O365SendEvent(name='send_event', description='Use this tool to create and send an event with the provided event fields.', args_schema=<class 'langchain_community.tools.office365.send_event.SendEventSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, handle_tool_error=False, account=Account Client Id: f32a022c-3c4c-4d10-a9d8-f6a9a9055302),
O365SendMessage(name='send_email', description='Use this tool to send an email with the provided message fields.', args_schema=<class 'langchain_community.tools.office365.send_message.SendMessageSchema'>, return_direct=False, verbose=False, callbacks=None, callback_manager=None, handle_tool_error=False, account=Account Client Id: f32a022c-3c4c-4d10-a9d8-f6a9a9055302)]
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,
verbose=False,
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
)
Copy
agent.run(
"Create an email draft for me to edit of a letter from the perspective of a sentient parrot"
" who is looking to collaborate on some research with her"
" estranged friend, a cat. Under no circumstances may you send the message, however."
)
Copy
'The draft email was created correctly.'
Copy
agent.run(
"Could you search in my drafts folder and let me know if any of them are about collaboration?"
)
Copy
"I found one draft in your drafts folder about collaboration. It was sent on 2023-06-16T18:22:17+0000 and the subject was 'Collaboration Request'."
Copy
agent.run(
"Can you schedule a 30 minute meeting with a sentient parrot to discuss research collaborations on October 3, 2023 at 2 pm Easter Time?"
)
Copy
/home/vscode/langchain-py-env/lib/python3.11/site-packages/O365/utils/windows_tz.py:639: PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider. For more details on how to do so, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
iana_tz.zone if isinstance(iana_tz, tzinfo) else iana_tz)
/home/vscode/langchain-py-env/lib/python3.11/site-packages/O365/utils/utils.py:463: PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider. For more details on how to do so, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
timezone = date_time.tzinfo.zone if date_time.tzinfo is not None else None
Copy
'I have scheduled a meeting with a sentient parrot to discuss research collaborations on October 3, 2023 at 2 pm Easter Time. Please let me know if you need to make any changes.'
Copy
agent.run(
"Can you tell me if I have any events on October 3, 2023 in Eastern Time, and if so, tell me if any of them are with a sentient parrot?"
)
Copy
"Yes, you have an event on October 3, 2023 with a sentient parrot. The event is titled 'Meeting with sentient parrot' and is scheduled from 6:00 PM to 6:30 PM."
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.