이 notebook은 Infobip API wrapper를 사용하여 SMS 메시지와 이메일을 보내는 방법을 보여줍니다. Infobip은 다양한 서비스를 제공하지만, 이 notebook은 SMS와 Email 서비스에 중점을 둡니다. API 및 기타 채널에 대한 자세한 정보는 여기에서 확인할 수 있습니다.

Setup

이 도구를 사용하려면 Infobip 계정이 필요합니다. 무료 체험 계정을 생성할 수 있습니다. InfobipAPIWrapper는 자격 증명을 제공할 수 있는 name parameter를 사용합니다:
  • infobip_api_key - developer tools에서 찾을 수 있는 API Key
  • infobip_base_url - Infobip API의 Base url. 기본값 https://api.infobip.com/을 사용할 수 있습니다.
infobip_api_keyinfobip_base_url을 환경 변수 INFOBIP_API_KEYINFOBIP_BASE_URL로 제공할 수도 있습니다.

SMS 보내기

from langchain_community.utilities.infobip import InfobipAPIWrapper

infobip: InfobipAPIWrapper = InfobipAPIWrapper()

infobip.run(
    to="41793026727",
    text="Hello, World!",
    sender="LangChain",
    channel="sms",
)

Email 보내기

from langchain_community.utilities.infobip import InfobipAPIWrapper

infobip: InfobipAPIWrapper = InfobipAPIWrapper()

infobip.run(
    to="[email protected]",
    sender="[email protected]",
    subject="example",
    body="example",
    channel="email",
)

Agent 내에서 사용하는 방법

from langchain_classic import hub
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_community.utilities.infobip import InfobipAPIWrapper
from langchain.tools import StructuredTool
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field

instructions = "You are a coding teacher. You are teaching a student how to code. The student asks you a question. You answer the question."
base_prompt = hub.pull("langchain-ai/openai-functions-template")
prompt = base_prompt.partial(instructions=instructions)
llm = ChatOpenAI(temperature=0)


class EmailInput(BaseModel):
    body: str = Field(description="Email body text")
    to: str = Field(description="Email address to send to. Example: [email protected]")
    sender: str = Field(
        description="Email address to send from, must be '[email protected]'"
    )
    subject: str = Field(description="Email subject")
    channel: str = Field(description="Email channel, must be 'email'")


infobip_api_wrapper: InfobipAPIWrapper = InfobipAPIWrapper()
infobip_tool = StructuredTool.from_function(
    name="infobip_email",
    description="Send Email via Infobip. If you need to send email, use infobip_email",
    func=infobip_api_wrapper.run,
    args_schema=EmailInput,
)
tools = [infobip_tool]

agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
    agent=agent,
    tools=tools,
    verbose=True,
)

agent_executor.invoke(
    {
        "input": "Hi, can you please send me an example of Python recursion to my email [email protected]"
    }
)
> Entering new AgentExecutor chain...

Invoking: `infobip_email` with `{'body': 'Hi,\n\nHere is a simple example of a recursive function in Python:\n\n```\ndef factorial(n):\n    if n == 1:\n        return 1\n    else:\n        return n * factorial(n-1)\n```\n\nThis function calculates the factorial of a number. The factorial of a number is the product of all positive integers less than or equal to that number. The function calls itself with a smaller argument until it reaches the base case where n equals 1.\n\nBest,\nCoding Teacher', 'to': '[email protected]', 'sender': '[email protected]', 'subject': 'Python Recursion Example', 'channel': 'email'}`


I have sent an example of Python recursion to your email. Please check your inbox.

> Finished chain.

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I