An integration package connecting Cloudsway and LangChain
Project description
langchain-cloudsway
This package contains the LangChain integration with Cloudsway.
Installation
pip install -U langchain-cloudsway
Configuration
Set your Cloudsway API credentials as an environment variable:
# POSIX / Git Bash
export CLOUDSWAY_SERVER_KEY="endpoint-accesskey"
# Windows (cmd.exe)
set CLOUDSWAY_SERVER_KEY=endpoint-accesskey
The value should be in the format:
endpoint-accesskey
To get your token and subscribe to a plan, please register at https://console.cloudsway.ai/.
Tool
SmartsearchTool provides web search via the Cloudsway API.
Basic Usage
from langchain_cloudsway.smartsearch import SmartsearchTool
tool = SmartsearchTool()
result = tool.invoke({
"query": "cloudsway.ai",
"count": 5,
"setLang": "en",
})
print(result)
Available Parameters
Notes:
- Query should not be empty. Recommended max length: 100 characters.
- count default: 10, valid range: 1–100.
- setLang supports 2- or 4-letter ISO codes. Default behavior is automatic language detection if not provided.
- mainText will only be returned when enableContent is true.
- safeSearch controls adult-content filtering. Allowed values: Off, Moderate, Strict.
| Parameter | Required | Type | Description |
|---|---|---|---|
| q / query | Yes | String | Search query string. Cannot be empty. (Recommended ≤ 100 chars) |
| count | No | Integer | Number of results to return. Default: 10. Range: 1–100. |
| offset | No | Integer | Zero-based result offset. Default: 0 (start position). |
| freshness | No | String | Time filter for results. Allowed values: Day, Week, Month. Default: no time filter. |
| setLang | No | String | UI language code (ISO 639-1 or ISO 639-1 + '-' + ISO 3166). Default: auto detect. |
| sites | No | String | Host address filter (e.g., baijiahao.baidu.com). |
| enableContent | No | Boolean | Whether to return full content. Default: false. Must be true to return mainText. |
| mainText | No | Boolean | Whether to return long summary (mainText). Requires enableContent=true. Default: false. |
| safeSearch | No | String | Adult-content filter. One of: Off, Moderate, Strict. Default: not set (server default). |
Advanced Usage Examples
# Search with freshness and explicit language
result = tool.invoke({
"query": "latest AI research",
"count": 20,
"freshness": "Week",
"setLang": "en-US"
})
# Search within a specific site and fetch full content + mainText
result = tool.invoke({
"query": "machine learning tutorial",
"sites": "github.com",
"enableContent": True,
"mainText": True,
})
# Paginated search
result = tool.invoke({
"query": "climate change",
"count": 10,
"offset": 10 # get next page of results
})
Response Structure
The API returns JSON similar to:
{
"queryContext": {
"originalQuery": "your search query"
},
"webPages": {
"value": [
{
"name": "Page Title",
"snippet": "Short description... (first 200 characters)",
"url": "https://example.com/page",
"displayUrl": "example.com/page",
"thumbnailUrl": "https://example.com/thumbnail.jpg",
"datePublished": "2025-07-14T00:00:00.0000000",
"datePublishedDisplayText": "Jul 14, 2025",
"dateLastCrawled": "2025-07-15T02:48:00.0000000Z",
"siteName": "Example Website",
"score": 0.95,
"mainText": "Longer extracted summary or main content (present when enableContent=true and mainText=true)"
}
]
}
}
Response Field Notes
- queryContext.originalQuery: Original search term.
- webPages.value: Array of search results.
- Each WebPage may include:
- name, url, displayUrl, snippet
- datePublished, dateLastCrawled (when available)
- siteName, thumbnailUrl, score
- mainText: long summary (only present when enabled)
Error Handling
Common status codes:
- 200: Success
- 429: Rate limit exceeded (QPS limit). Contact Cloudsway support for higher QPS.
If you encounter any problems, reach out to info@cloudsway.com.
License
This project is open-sourced under the MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_cloudsway-0.1.2.tar.gz.
File metadata
- Download URL: langchain_cloudsway-0.1.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ca3a76ad5d58cdba360e417676b1e94686b980a3c78f7a21f1e2494ff28854a
|
|
| MD5 |
e1e565e33701bff7adf2595208d3f01c
|
|
| BLAKE2b-256 |
b496e002f512648bd30ad6e836cb1ea4e709cdf99c5294784a89894c4ba75c84
|
File details
Details for the file langchain_cloudsway-0.1.2-py3-none-any.whl.
File metadata
- Download URL: langchain_cloudsway-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fdce5a742106704393e5788293431764af31e27c816fcbeaded855e810bf84a
|
|
| MD5 |
5ba2396359f300b514ac144d6984bde3
|
|
| BLAKE2b-256 |
2ec5aee270587a7b12be3be24bd2528b51af6dd2826807a4651ad1aea6e3c1c4
|