From e4b2a90c0a33e2bf3aa2e8b93fcf38386f074769 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Jul 2025 09:32:04 +0800 Subject: [PATCH 1/3] docs: add langchain-cloudsway provider doc, tools doc and provider entry to packages.yml --- .../integrations/providers/cloudsway.ipynb | 54 ++++ docs/docs/integrations/tools/cloudsway.ipynb | 255 ++++++++++++++++++ libs/packages.yml | 3 + 3 files changed, 312 insertions(+) create mode 100644 docs/docs/integrations/providers/cloudsway.ipynb create mode 100644 docs/docs/integrations/tools/cloudsway.ipynb diff --git a/docs/docs/integrations/providers/cloudsway.ipynb b/docs/docs/integrations/providers/cloudsway.ipynb new file mode 100644 index 00000000000..b756e7a3dca --- /dev/null +++ b/docs/docs/integrations/providers/cloudsway.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Cloudsway\n", + "\n", + "Cloudsway is a platform that provides advanced web search capabilities for LangChain applications via its SmartsearchTool. It enables efficient, multi-language, safe, and structured web search for LLM-powered workflows.\n", + "\n", + "## Installation\n", + "\n", + "Install the integration package:\n", + "```bash\n", + "pip install langchain-cloudsway\n", + "```\n", + "\n", + "## Configuration\n", + "\n", + "Set your Cloudsway API credentials as an environment variable:\n", + "\n", + "```bash\n", + "export CLOUDSWAY_SERVER_KEY=\"your-endpoint-accesskey\"\n", + "```\n", + "\n", + "The value should be in the format: \n", + "`endpoint-accesskey` \n", + " \n", + "To get your token and subscribe to a plan, please register at [console.cloudsway.ai](console.cloudsway.ai).\n", + "\n", + "\n", + "## Supported Components\n", + "\n", + "- **SmartsearchTool**: Advanced web search tool for structured results.\n", + "\n", + "## API Reference\n", + "\n", + "See [GitHub](https://github.com/Cloudsway-AI/langchain-cloudsway) for full documentation.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/docs/integrations/tools/cloudsway.ipynb b/docs/docs/integrations/tools/cloudsway.ipynb new file mode 100644 index 00000000000..76d02846f20 --- /dev/null +++ b/docs/docs/integrations/tools/cloudsway.ipynb @@ -0,0 +1,255 @@ +{ + "cells": [ + { + "cell_type": "raw", + "id": "10238e62-3465-4973-9279-606cbb7ccf16", + "metadata": { + "vscode": { + "languageId": "raw" + } + }, + "source": [ + "---\n", + "sidebar_label: SmartsearchTool\n", + "---" + ] + }, + { + "cell_type": "markdown", + "id": "a6f91f20", + "metadata": {}, + "source": [ + "# SmartsearchTool\n", + "\n", + "This notebook provides a quick overview for getting started with SmartsearchTool. For detailed documentation, see the [API reference](https://github.com/Cloudsway-AI/langchain-cloudsway).\n", + "\n", + "## Overview\n", + "\n", + "### Integration details\n", + "\n", + "| Class | Package | Serializable | JS support | PyPI Version |\n", + "| :--- | :--- | :---: | :---: | :---: |\n", + "| [SmartsearchTool](https://github.com/Cloudsway-AI/langchain-cloudsway) | langchain-cloudsway | ✅ | ❌ | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-cloudsway?style=flat-square&label=%20) |\n", + "\n", + "### Tool features\n", + "\n", + "- Keyword-based web search\n", + "- Configurable result count, language, and safety level\n", + "- Structured JSON output\n", + "- No personal data collected\n", + "\n", + "\n", + "## Setup\n", + "\n", + "The integration lives in the `langchain-cloudsway` package." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f85b4089", + "metadata": {}, + "outputs": [], + "source": [ + "%pip install --quiet -U langchain-cloudsway" + ] + }, + { + "cell_type": "markdown", + "id": "b15e9266", + "metadata": {}, + "source": [ + "### Credentials\n", + "\n", + "- TODO: Add any credentials that are needed" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0b178a2-8816-40ca-b57c-ccdd86dde9c9", + "metadata": {}, + "outputs": [], + "source": [ + "import getpass\n", + "import os\n", + "\n", + "if not os.environ.get(\"CLOUDSWAY_SERVER_KEY\"):\n", + " os.environ[\"CLOUDSWAY_SERVER_KEY\"] = getpass.getpass(\"CLOUDSWAY API key:\\n\")" + ] + }, + { + "cell_type": "markdown", + "id": "bc5ab717-fd27-4c59-b912-bdd099541478", + "metadata": {}, + "source": [ + "It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com/) for best-in-class observability:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a6c2f136-6367-4f1f-825d-ae741e1bf281", + "metadata": {}, + "outputs": [], + "source": [ + "os.environ[\"LANGSMITH_TRACING\"] = \"true\"\n", + "os.environ[\"LANGSMITH_API_KEY\"] = getpass.getpass()" + ] + }, + { + "cell_type": "markdown", + "id": "1c97218f-f366-479d-8bf7-fe9f2f6df73f", + "metadata": {}, + "source": [ + "## Instantiation\n", + "\n", + "| Name | Type | Required | Default | Description |\n", + "|--------------|---------|----------|-----------|--------------------------------------------------------------------|\n", + "| `query` | string | Yes | - | Search keyword or question (e.g., \"Latest advances in AI 2024\") |\n", + "| `count` | number | No | 10 | Number of results to return (1-50, recommended 3-10) |\n", + "| `offset` | number | No | 0 | Pagination offset (e.g., offset=10 means start from result #11) |\n", + "| `setLang` | string | No | \"en\" | Language filter (e.g., \"zh-CN\", \"en\", \"ja\") |\n", + "| `safeSearch` | string | No | \"Strict\" | Content safety level: \"Strict\", \"Moderate\", or \"Off\" |\n", + "\n", + "Here we show how to instantiate an instance of the SmartsearchTool tool, with " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b3ddfe9-ca79-494c-a7ab-1f56d9407a64", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_cloudsway.smartsearch import SmartsearchTool\n", + "\n", + "tool = SmartsearchTool()" + ] + }, + { + "cell_type": "markdown", + "id": "74147a1a", + "metadata": {}, + "source": [ + "## Invocation\n", + "\n", + "### [Invoke directly with args](/docs/concepts/tools/#use-the-tool-directly)\n", + "\n", + "The SmartsearchTool accepts the following arguments during invocation:\n", + "\n", + "- `query` (required): A natural language search query.\n", + "- The following arguments can also be set during invocation: `count`, `offset`, `setLang`, `safeSearch`.\n", + " - `count`: Number of results to return (default: 10, range: 1-50).\n", + " - `offset`: Pagination offset (default: 0).\n", + " - `setLang`: Language filter (e.g., `\"en\"`, `\"zh-CN\"`, `\"ja\"`; default: `\"en\"`).\n", + " - `safeSearch`: Content safety level (`\"Strict\"`, `\"Moderate\"`, `\"Off\"`; default: `\"Strict\"`).\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65310a8b-eb0c-4d9e-a618-4f4abe2414fc", + "metadata": {}, + "outputs": [], + "source": [ + "tool.invoke({\n", + " \"query\": \"2024 global AI summit highlights\"\n", + "})" + ] + }, + { + "cell_type": "markdown", + "id": "d6e73897", + "metadata": {}, + "source": [ + "### [Invoke with ToolCall](/docs/concepts/tool_calling/#tool-execution)\n", + "\n", + "We can also invoke the tool with a model-generated ToolCall, in which case a ToolMessage will be returned:\n" + ] + }, + { + "cell_type": "markdown", + "id": "3f2b33fd", + "metadata": {}, + "source": [ + "## Using with an Agent\n", + "\n", + "You can use SmartsearchTool directly with an agent executor by binding the tool to the agent. This allows the agent to dynamically set the available arguments for SmartsearchTool based on user input." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f90e33a7", + "metadata": {}, + "outputs": [], + "source": [ + "# Install dependencies\n", + "%pip install -qU langchain langchain-cloudsway langgraph\n", + "\n", + "import getpass\n", + "import os\n", + "\n", + "if not os.environ.get(\"DEEPSEEK_API_KEY\"):\n", + " os.environ[\"DEEPSEEK_API_KEY\"] = getpass.getpass(\"Enter API key for DeepSeek: \")\n", + "\n", + "if not os.environ.get(\"CLOUDSWAY_SERVER_KEY\"):\n", + " os.environ[\"CLOUDSWAY_SERVER_KEY\"] = getpass.getpass(\"CLOUDSWAY_SERVER_KEY:\\n\")\n", + "\n", + "from langchain.chat_models import init_chat_model\n", + "from langchain_cloudsway.smartsearch import SmartsearchTool\n", + "from langgraph.prebuilt import create_react_agent\n", + "\n", + "llm = init_chat_model(\"deepseek-chat\", model_provider=\"deepseek\")\n", + "\n", + "# Initialize SmartsearchTool\n", + "smartsearch_tool = SmartsearchTool(\n", + " # You can set defaults here, e.g. count=5, setLang=\"en\"\n", + ")\n", + "\n", + "# Create agent with the tool\n", + "agent = create_react_agent(llm, [smartsearch_tool])\n", + "\n", + "user_input = \"Show me recent peer-reviewed papers about autonomous vehicles from arxiv.org.\"\n", + "\n", + "for step in agent.stream(\n", + " {\"messages\": user_input},\n", + " stream_mode=\"values\",\n", + "):\n", + " step[\"messages\"][-1].pretty_print()" + ] + }, + { + "cell_type": "markdown", + "id": "4ac8146c", + "metadata": {}, + "source": [ + "## API reference\n", + "\n", + "For detailed documentation of all SmartsearchTool features and configurations head to the API reference: [https://github.com/Cloudsway-AI/langchain-cloudsway](https://github.com/Cloudsway-AI/langchain-cloudsway)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "poetry-venv-311", + "language": "python", + "name": "poetry-venv-311" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/libs/packages.yml b/libs/packages.yml index 163a8407421..f072225709e 100644 --- a/libs/packages.yml +++ b/libs/packages.yml @@ -696,3 +696,6 @@ packages: - name: langchain-tensorlake path: . repo: tensorlakeai/langchain-tensorlake +- name: langchain-cloudsway + repo: Cloudsway-AI/langchain-cloudsway + path: . \ No newline at end of file From 452de4c0db265d7d1f2838b5e1f1b320e9598a60 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Jul 2025 10:30:20 +0800 Subject: [PATCH 2/3] docs: add langchain-cloudsway provider doc, tools doc and provider entry to packages.yml --- docs/docs/integrations/tools/cloudsway.ipynb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/docs/integrations/tools/cloudsway.ipynb b/docs/docs/integrations/tools/cloudsway.ipynb index 76d02846f20..387de8fa96d 100644 --- a/docs/docs/integrations/tools/cloudsway.ipynb +++ b/docs/docs/integrations/tools/cloudsway.ipynb @@ -153,9 +153,7 @@ "metadata": {}, "outputs": [], "source": [ - "tool.invoke({\n", - " \"query\": \"2024 global AI summit highlights\"\n", - "})" + "tool.invoke({\"query\": \"2024 global AI summit highlights\"})" ] }, { @@ -173,7 +171,7 @@ "id": "3f2b33fd", "metadata": {}, "source": [ - "## Using with an Agent\n", + "## Use within an agent\n", "\n", "You can use SmartsearchTool directly with an agent executor by binding the tool to the agent. This allows the agent to dynamically set the available arguments for SmartsearchTool based on user input." ] @@ -192,7 +190,7 @@ "import os\n", "\n", "if not os.environ.get(\"DEEPSEEK_API_KEY\"):\n", - " os.environ[\"DEEPSEEK_API_KEY\"] = getpass.getpass(\"Enter API key for DeepSeek: \")\n", + " os.environ[\"DEEPSEEK_API_KEY\"] = getpass.getpass(\"Enter API key for DeepSeek: \")\n", "\n", "if not os.environ.get(\"CLOUDSWAY_SERVER_KEY\"):\n", " os.environ[\"CLOUDSWAY_SERVER_KEY\"] = getpass.getpass(\"CLOUDSWAY_SERVER_KEY:\\n\")\n", @@ -211,8 +209,9 @@ "# Create agent with the tool\n", "agent = create_react_agent(llm, [smartsearch_tool])\n", "\n", - "user_input = \"Show me recent peer-reviewed papers about autonomous vehicles from arxiv.org.\"\n", - "\n", + "user_input = (\n", + " \"Show me recent peer-reviewed papers about autonomous vehicles from arxiv.org.\"\n", + ")\n", "for step in agent.stream(\n", " {\"messages\": user_input},\n", " stream_mode=\"values\",\n", From 647e592972e1e684aa53ee299b4e267e8b707322 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Jul 2025 11:14:11 +0800 Subject: [PATCH 3/3] docs: add langchain-cloudsway provider doc, tools doc and provider entry to packages.yml --- docs/docs/integrations/providers/cloudsway.ipynb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/docs/integrations/providers/cloudsway.ipynb b/docs/docs/integrations/providers/cloudsway.ipynb index b756e7a3dca..38146334de2 100644 --- a/docs/docs/integrations/providers/cloudsway.ipynb +++ b/docs/docs/integrations/providers/cloudsway.ipynb @@ -26,7 +26,7 @@ "The value should be in the format: \n", "`endpoint-accesskey` \n", " \n", - "To get your token and subscribe to a plan, please register at [console.cloudsway.ai](console.cloudsway.ai).\n", + "To get your token and subscribe to a plan, please register at [console.cloudsway.ai](https://console.cloudsway.ai/).\n", "\n", "\n", "## Supported Components\n", @@ -37,11 +37,6 @@ "\n", "See [GitHub](https://github.com/Cloudsway-AI/langchain-cloudsway) for full documentation.\n" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] } ], "metadata": {