From 369e90d42744a8a8c4877de3d02c83b0927f74c9 Mon Sep 17 00:00:00 2001 From: Lance Martin <122662504+rlancemartin@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:33:13 -0800 Subject: [PATCH] docs: Minor update to Robocorp toolkit docs (#16399) --- .../docs/integrations/toolkits/robocorp.ipynb | 101 ++++++++++++++++-- 1 file changed, 91 insertions(+), 10 deletions(-) diff --git a/docs/docs/integrations/toolkits/robocorp.ipynb b/docs/docs/integrations/toolkits/robocorp.ipynb index 56db35cc5ca..2dc39ea75e6 100644 --- a/docs/docs/integrations/toolkits/robocorp.ipynb +++ b/docs/docs/integrations/toolkits/robocorp.ipynb @@ -9,9 +9,11 @@ "\n", "This notebook covers how to get started with [Robocorp Action Server](https://github.com/robocorp/robocorp) action toolkit and LangChain.\n", "\n", + "Robocorp is the easiest way to extend the capabilities of AI agents, assistants and copilots with custom actions.\n", + "\n", "## Installation\n", "\n", - "First, see the [Robocorp Quickstart](https://github.com/robocorp/robocorp#quickstart) on how to setup Action Server and create your Actions.\n", + "First, see the [Robocorp Quickstart](https://github.com/robocorp/robocorp#quickstart) on how to setup `Action Server` and create your Actions.\n", "\n", "In your LangChain application, install the `langchain-robocorp` package: " ] @@ -20,13 +22,61 @@ "cell_type": "code", "execution_count": null, "id": "4c3bef91", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "# Install package\n", "%pip install --upgrade --quiet langchain-robocorp" ] }, + { + "cell_type": "markdown", + "id": "dd53ad19-4a62-46d1-a2f7-151cfd282590", + "metadata": {}, + "source": [ + "When you create the new `Action Server` following the above quickstart.\n", + "\n", + "It will create a directory with files, including `action.py`.\n", + "\n", + "We can add python function as actions as shown [here](https://github.com/robocorp/robocorp/tree/master/actions#describe-your-action).\n", + "\n", + "Let's add a dummy function to `action.py`.\n", + "\n", + "```\n", + "@action\n", + "def get_weather_forecast(city: str, days: int, scale: str = \"celsius\") -> str:\n", + " \"\"\"\n", + " Returns weather conditions forecast for a given city.\n", + "\n", + " Args:\n", + " city (str): Target city to get the weather conditions for\n", + " days: How many day forecast to return\n", + " scale (str): Temperature scale to use, should be one of \"celsius\" or \"fahrenheit\"\n", + "\n", + " Returns:\n", + " str: The requested weather conditions forecast\n", + " \"\"\"\n", + " return \"75F and sunny :)\"\n", + "```\n", + "\n", + "We then start the server:\n", + "\n", + "```\n", + "action-server start\n", + "```\n", + "\n", + "And we can see: \n", + "\n", + "```\n", + "Found new action: get_weather_forecast\n", + "\n", + "```\n", + "\n", + "Test locally by going to the server running at `http://localhost:8080` and use the UI to run the function." + ] + }, { "cell_type": "markdown", "id": "2b4f3e15", @@ -38,17 +88,47 @@ "\n", "- `LANGCHAIN_TRACING_V2=true`: To enable LangSmith log run tracing that can also be bind to respective Action Server action run logs. See [LangSmith documentation](https://docs.smith.langchain.com/tracing#log-runs) for more.\n", "\n", - "## Usage" + "## Usage\n", + "\n", + "We started the local action server, above, running on `http://localhost:8080`." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "62e0dbc3", "metadata": { "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "\n", + "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n", + "\u001b[32;1m\u001b[1;3m\n", + "Invoking: `robocorp_action_server_get_weather_forecast` with `{'city': 'San Francisco', 'days': 1, 'scale': 'fahrenheit'}`\n", + "\n", + "\n", + "\u001b[0m\u001b[33;1m\u001b[1;3m\"75F and sunny :)\"\u001b[0m\u001b[32;1m\u001b[1;3mThe current weather today in San Francisco is 75F and sunny.\u001b[0m\n", + "\n", + "\u001b[1m> Finished chain.\u001b[0m\n" + ] + }, + { + "data": { + "text/plain": [ + "{'input': 'What is the current weather today in San Francisco in fahrenheit?',\n", + " 'output': 'The current weather today in San Francisco is 75F and sunny.'}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from langchain.agents import AgentExecutor, OpenAIFunctionsAgent\n", "from langchain.chat_models import ChatOpenAI\n", @@ -69,8 +149,7 @@ "\n", "executor = AgentExecutor(agent=agent, tools=tools, verbose=True)\n", "\n", - "\n", - "executor.invoke(\"What is the current date?\")" + "executor.invoke(\"What is the current weather today in San Francisco in fahrenheit?\")" ] }, { @@ -80,12 +159,14 @@ "source": [ "### Single input tools\n", "\n", - "By default `toolkit.get_tools()` will return the actions as Structured Tools. To return single input tools, pass a Chat model to be used for processing the inputs." + "By default `toolkit.get_tools()` will return the actions as Structured Tools. \n", + "\n", + "To return single input tools, pass a Chat model to be used for processing the inputs." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "1dc7db86", "metadata": {}, "outputs": [], @@ -112,7 +193,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.5" + "version": "3.9.16" } }, "nbformat": 4,