arcade-mcp/examples/call_a_tool_directly.py
Eric Gustin 081865733a
Add examples (#136)
## PR Description
This PR adds 7 examples.

* `call_a_tool_directly_with_auth.py` - Simple example that uses Arcade
client to execute a tool that lists Gmail emails
* `call_a_tool_directly.py` - Simple example that uses Arcade client to
execute a tool that adds two numbers together
* `call_a_tool_with_llm.py` - Simple example that uses the LLM api to
star the arcade-ai repository
* `get_auth_token.py` - Simple example that gets a Google auth token and
then calls the Google API
* `call_multiple_tools_directly_with_auth.py` - A more involved example
that directly calls multiple spotify tools sequentially
* `call_multiple_tools_with_llm.py` - A more involved example that uses
an llm to call multiple spotify tools sequentially
* `simple_chatbot.py` - Simple chatbot that uses arcade tools and has
history

---------

Co-authored-by: Nate Barbettini <nathanaelb@gmail.com>
2024-11-06 11:02:41 -08:00

40 lines
1.4 KiB
Python

"""
This example demonstrates how to directly call a tool that does not require authorization.
"""
from arcadepy import Arcade # pip install arcade-py
def call_non_auth_tool(client: Arcade, user_id: str) -> None:
"""Directly call a prebuilt tool that does not require authorization.
In this example, we are
1. Preparing the inputs to the Math.Add tool
2. Executing the tool
3. Printing the output of the tool's execution, i.e., the result of adding 9001 and 42
This is a simple example of calling a non-auth tool. Next, try writing your own non-auth tool for your own use case.
"""
# Prepare the inputs to the tool as a dictionary where keys are the names of the parameters expected by the tool and the values are the actual values to pass to the tool
inputs = {"a": 9001, "b": 42}
# Execute the tool
response = client.tools.execute(
tool_name="Math.Add",
inputs=inputs,
user_id=user_id,
)
# Print the output of the tool execution
print(response.output.value)
if __name__ == "__main__":
cloud_host = "https://api.arcade-ai.com"
client = Arcade(
base_url=cloud_host, # Alternatively, use http://localhost:9099 if you are running Arcade Engine locally, or any base_url if you're hosting elsewhere
)
user_id = "you@example.com"
call_non_auth_tool(client, user_id)