mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
Zapier update oauth support (#6780)
Description: Update documentation to 1) point to updated documentation links at Zapier.com (we've revamped our help docs and paths), and 2) To provide clarity how to use the wrapper with an access token for OAuth support Demo: Initializing the Zapier Wrapper with an OAuth Access Token `ZapierNLAWrapper(zapier_nla_oauth_access_token="<redacted>")` Using LangChain to resolve the current weather in Vancouver BC leveraging Zapier NLA to lookup weather by coords. ``` > Entering new chain... I need to use a tool to get the current weather. Action: The Weather: Get Current Weather Action Input: Get the current weather for Vancouver BC Observation: {"coord__lon": -123.1207, "coord__lat": 49.2827, "weather": [{"id": 802, "main": "Clouds", "description": "scattered clouds", "icon": "03d", "icon_url": "http://openweathermap.org/img/wn/03d@2x.png"}], "weather[]icon_url": ["http://openweathermap.org/img/wn/03d@2x.png"], "weather[]icon": ["03d"], "weather[]id": [802], "weather[]description": ["scattered clouds"], "weather[]main": ["Clouds"], "base": "stations", "main__temp": 71.69, "main__feels_like": 71.56, "main__temp_min": 67.64, "main__temp_max": 76.39, "main__pressure": 1015, "main__humidity": 64, "visibility": 10000, "wind__speed": 3, "wind__deg": 155, "wind__gust": 11.01, "clouds__all": 41, "dt": 1687806607, "sys__type": 2, "sys__id": 2011597, "sys__country": "CA", "sys__sunrise": 1687781297, "sys__sunset": 1687839730, "timezone": -25200, "id": 6173331, "name": "Vancouver", "cod": 200, "summary": "scattered clouds", "_zap_search_was_found_status": true} Thought: I now know the current weather in Vancouver BC. Final Answer: The current weather in Vancouver BC is scattered clouds with a temperature of 71.69 and wind speed of 3 ```
This commit is contained in:
parent
24e4ae95ba
commit
da462d9dd4
@ -7,7 +7,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# Zapier Natural Language Actions API\n",
|
"# Zapier Natural Language Actions API\n",
|
||||||
"\\\n",
|
"\\\n",
|
||||||
"Full docs here: https://nla.zapier.com/api/v1/docs\n",
|
"Full docs here: https://nla.zapier.com/start/\n",
|
||||||
"\n",
|
"\n",
|
||||||
"**Zapier Natural Language Actions** gives you access to the 5k+ apps, 20k+ actions on Zapier's platform through a natural language API interface.\n",
|
"**Zapier Natural Language Actions** gives you access to the 5k+ apps, 20k+ actions on Zapier's platform through a natural language API interface.\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -21,7 +21,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"2. User-facing (Oauth): for production scenarios where you are deploying an end-user facing application and LangChain needs access to end-user's exposed actions and connected accounts on Zapier.com\n",
|
"2. User-facing (Oauth): for production scenarios where you are deploying an end-user facing application and LangChain needs access to end-user's exposed actions and connected accounts on Zapier.com\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This quick start will focus on the server-side use case for brevity. Review [full docs](https://nla.zapier.com/api/v1/docs) or reach out to nla@zapier.com for user-facing oauth developer support.\n",
|
"This quick start will focus on the server-side use case for brevity. Review [full docs](https://nla.zapier.com/start/) for user-facing oauth developer support.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This example goes over how to use the Zapier integration with a `SimpleSequentialChain`, then an `Agent`.\n",
|
"This example goes over how to use the Zapier integration with a `SimpleSequentialChain`, then an `Agent`.\n",
|
||||||
"In code, below:"
|
"In code, below:"
|
||||||
@ -39,7 +39,7 @@
|
|||||||
"# get from https://platform.openai.com/\n",
|
"# get from https://platform.openai.com/\n",
|
||||||
"os.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"\")\n",
|
"os.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# get from https://nla.zapier.com/demo/provider/debug (under User Information, after logging in):\n",
|
"# get from https://nla.zapier.com/docs/authentication/ after logging in):\n",
|
||||||
"os.environ[\"ZAPIER_NLA_API_KEY\"] = os.environ.get(\"ZAPIER_NLA_API_KEY\", \"\")"
|
"os.environ[\"ZAPIER_NLA_API_KEY\"] = os.environ.get(\"ZAPIER_NLA_API_KEY\", \"\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""## Zapier Natural Language Actions API
|
"""## Zapier Natural Language Actions API
|
||||||
\
|
\
|
||||||
Full docs here: https://nla.zapier.com/api/v1/docs
|
Full docs here: https://nla.zapier.com/start/
|
||||||
|
|
||||||
**Zapier Natural Language Actions** gives you access to the 5k+ apps, 20k+ actions
|
**Zapier Natural Language Actions** gives you access to the 5k+ apps, 20k+ actions
|
||||||
on Zapier's platform through a natural language API interface.
|
on Zapier's platform through a natural language API interface.
|
||||||
@ -24,8 +24,8 @@ NLA offers both API Key and OAuth for signing NLA API requests.
|
|||||||
connected accounts on Zapier.com
|
connected accounts on Zapier.com
|
||||||
|
|
||||||
This quick start will focus on the server-side use case for brevity.
|
This quick start will focus on the server-side use case for brevity.
|
||||||
Review [full docs](https://nla.zapier.com/api/v1/docs) or reach out to
|
Review [full docs](https://nla.zapier.com/start/) for user-facing oauth developer
|
||||||
nla@zapier.com for user-facing oauth developer support.
|
support.
|
||||||
|
|
||||||
Typically, you'd use SequentialChain, here's a basic example:
|
Typically, you'd use SequentialChain, here's a basic example:
|
||||||
|
|
||||||
@ -42,8 +42,7 @@ import os
|
|||||||
# get from https://platform.openai.com/
|
# get from https://platform.openai.com/
|
||||||
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "")
|
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "")
|
||||||
|
|
||||||
# get from https://nla.zapier.com/demo/provider/debug
|
# get from https://nla.zapier.com/docs/authentication/
|
||||||
# (under User Information, after logging in):
|
|
||||||
os.environ["ZAPIER_NLA_API_KEY"] = os.environ.get("ZAPIER_NLA_API_KEY", "")
|
os.environ["ZAPIER_NLA_API_KEY"] = os.environ.get("ZAPIER_NLA_API_KEY", "")
|
||||||
|
|
||||||
from langchain.llms import OpenAI
|
from langchain.llms import OpenAI
|
||||||
@ -61,8 +60,9 @@ from langchain.utilities.zapier import ZapierNLAWrapper
|
|||||||
|
|
||||||
llm = OpenAI(temperature=0)
|
llm = OpenAI(temperature=0)
|
||||||
zapier = ZapierNLAWrapper()
|
zapier = ZapierNLAWrapper()
|
||||||
## To leverage a nla_oauth_access_token you may pass the value to the ZapierNLAWrapper
|
## To leverage OAuth you may pass the value `nla_oauth_access_token` to
|
||||||
## If you do this there is no need to initialize the ZAPIER_NLA_API_KEY env variable
|
## the ZapierNLAWrapper. If you do this there is no need to initialize
|
||||||
|
## the ZAPIER_NLA_API_KEY env variable
|
||||||
# zapier = ZapierNLAWrapper(zapier_nla_oauth_access_token="TOKEN_HERE")
|
# zapier = ZapierNLAWrapper(zapier_nla_oauth_access_token="TOKEN_HERE")
|
||||||
toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier)
|
toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier)
|
||||||
agent = initialize_agent(
|
agent = initialize_agent(
|
||||||
@ -99,7 +99,7 @@ class ZapierNLARunAction(BaseTool):
|
|||||||
(eg. "get the latest email from Mike Knoop" for "Gmail: find email" action)
|
(eg. "get the latest email from Mike Knoop" for "Gmail: find email" action)
|
||||||
params: a dict, optional. Any params provided will *override* AI guesses
|
params: a dict, optional. Any params provided will *override* AI guesses
|
||||||
from `instructions` (see "understanding the AI guessing flow" here:
|
from `instructions` (see "understanding the AI guessing flow" here:
|
||||||
https://nla.zapier.com/api/v1/docs)
|
https://nla.zapier.com/docs/using-the-api#ai-guessing)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Util that can interact with Zapier NLA.
|
"""Util that can interact with Zapier NLA.
|
||||||
|
|
||||||
Full docs here: https://nla.zapier.com/api/v1/docs
|
Full docs here: https://nla.zapier.com/start/
|
||||||
|
|
||||||
Note: this wrapper currently only implemented the `api_key` auth method for testing
|
Note: this wrapper currently only implemented the `api_key` auth method for testing
|
||||||
and server-side production use cases (using the developer's connected accounts on
|
and server-side production use cases (using the developer's connected accounts on
|
||||||
@ -24,16 +24,20 @@ from langchain.utils import get_from_dict_or_env
|
|||||||
class ZapierNLAWrapper(BaseModel):
|
class ZapierNLAWrapper(BaseModel):
|
||||||
"""Wrapper for Zapier NLA.
|
"""Wrapper for Zapier NLA.
|
||||||
|
|
||||||
Full docs here: https://nla.zapier.com/api/v1/docs
|
Full docs here: https://nla.zapier.com/start/
|
||||||
|
|
||||||
Note: this wrapper currently only implemented the `api_key` auth method for
|
This wrapper supports both API Key and OAuth Credential auth methods. API Key
|
||||||
testingand server-side production use cases (using the developer's connected
|
is the fastest way to get started using this wrapper.
|
||||||
accounts on Zapier.com)
|
|
||||||
|
Call this wrapper with either `zapier_nla_api_key` or
|
||||||
|
`zapier_nla_oauth_access_token` arguments, or set the `ZAPIER_NLA_API_KEY`
|
||||||
|
environment variable. If both arguments are set, the Access Token will take
|
||||||
|
precedence.
|
||||||
|
|
||||||
For use-cases where LangChain + Zapier NLA is powering a user-facing application,
|
For use-cases where LangChain + Zapier NLA is powering a user-facing application,
|
||||||
and LangChain needs access to the end-user's connected accounts on Zapier.com,
|
and LangChain needs access to the end-user's connected accounts on Zapier.com,
|
||||||
you'll need to use oauth. Review the full docs above and reach out to
|
you'll need to use OAuth. Review the full docs above to learn how to create
|
||||||
nla@zapier.com for developer support.
|
your own provider and generate credentials.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
zapier_nla_api_key: str
|
zapier_nla_api_key: str
|
||||||
@ -120,7 +124,7 @@ class ZapierNLAWrapper(BaseModel):
|
|||||||
`params` will always contain an `instructions` key, the only required
|
`params` will always contain an `instructions` key, the only required
|
||||||
param. All others optional and if provided will override any AI guesses
|
param. All others optional and if provided will override any AI guesses
|
||||||
(see "understanding the AI guessing flow" here:
|
(see "understanding the AI guessing flow" here:
|
||||||
https://nla.zapier.com/api/v1/docs)
|
https://nla.zapier.com/docs/using-the-api#ai-guessing)
|
||||||
"""
|
"""
|
||||||
session = self._get_session()
|
session = self._get_session()
|
||||||
response = session.get(self.zapier_nla_api_base + "exposed/")
|
response = session.get(self.zapier_nla_api_base + "exposed/")
|
||||||
|
@ -50,3 +50,19 @@ def test_custom_base_prompt_fail() -> None:
|
|||||||
base_prompt=base_prompt,
|
base_prompt=base_prompt,
|
||||||
api_wrapper=ZapierNLAWrapper(zapier_nla_api_key="test"),
|
api_wrapper=ZapierNLAWrapper(zapier_nla_api_key="test"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_wrapper_fails_no_api_key_or_access_token_initialization() -> None:
|
||||||
|
"""Test Wrapper requires either an API Key or OAuth Access Token."""
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
ZapierNLAWrapper()
|
||||||
|
|
||||||
|
|
||||||
|
def test_wrapper_api_key_initialization() -> None:
|
||||||
|
"""Test Wrapper initializes with an API Key."""
|
||||||
|
ZapierNLAWrapper(zapier_nla_api_key="test")
|
||||||
|
|
||||||
|
|
||||||
|
def test_wrapper_access_token_initialization() -> None:
|
||||||
|
"""Test Wrapper initializes with an API Key."""
|
||||||
|
ZapierNLAWrapper(zapier_nla_oauth_access_token="test")
|
||||||
|
Loading…
Reference in New Issue
Block a user