mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-30 16:24:24 +00:00
Merge 647e592972
into 0e287763cd
This commit is contained in:
commit
ded6795e44
49
docs/docs/integrations/providers/cloudsway.ipynb
Normal file
49
docs/docs/integrations/providers/cloudsway.ipynb
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"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](https://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"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
254
docs/docs/integrations/tools/cloudsway.ipynb
Normal file
254
docs/docs/integrations/tools/cloudsway.ipynb
Normal file
@ -0,0 +1,254 @@
|
||||
{
|
||||
"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 | ✅ | ❌ |  |\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({\"query\": \"2024 global AI summit highlights\"})"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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": [
|
||||
"## 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."
|
||||
]
|
||||
},
|
||||
{
|
||||
"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 = (\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",
|
||||
"):\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
|
||||
}
|
@ -696,3 +696,6 @@ packages:
|
||||
- name: langchain-tensorlake
|
||||
path: .
|
||||
repo: tensorlakeai/langchain-tensorlake
|
||||
- name: langchain-cloudsway
|
||||
repo: Cloudsway-AI/langchain-cloudsway
|
||||
path: .
|
Loading…
Reference in New Issue
Block a user