Wetrocloud's Official SDK
Project description
Wetrocloud SDK
A powerful Python SDK for interacting with Wetrocloud's suite of AI and data processing services.
Table of Contents
- Installation
- Authentication
- Core Concepts
- Modules
- Examples
- Error Handling
- Advanced Usage
- API Reference
- Troubleshooting
Installation
pip install wetro
Authentication
Authentication with the Wetrocloud API requires an API key. You can provide this key when initializing any client.
from wetro import Wetrocloud
# Initialize the main client and access modules
client = Wetrocloud(api_key="your_api_key")
rag_client = client.rag
tools_client = client.tools
Core Concepts
The Wetrocloud SDK is organized into specialized modules that focus on different functionalities:
- RAG (Retrieval-Augmented Generation): Manage collections of documents and query them using natural language.
- Tools: Access utility functions including text generation, image processing, web extraction, and content categorization.
Each module can be used independently or together through the unified Wetrocloud client.
Modules
Wetrocloud Client
The main entry point that provides access to all functionality in the SDK.
from wetro import Wetrocloud
client = Wetrocloud(api_key="your_api_key")
# Access modules
rag_client = client.rag
tools_client = client.tools
RAG Module
The RAG (Retrieval-Augmented Generation) module allows you to create, manage, and query collections of documents.
Key Features
- Create and manage document collections
- Insert documents from various sources (web, text, files)
- Query collections using natural language
- Chat with context from your collections
- Structured output formatting with JSON schemas
Basic Usage
from wetro import WetroRAG
# Initialize RAG client
rag_client = WetroRAG(api_key="your_api_key")
# Set or create a collection
rag_client.collection.get_or_create_collection_id("my_unique_collection_id")
# Insert a web resource
insert_response = rag_client.collection.insert("https://example.com/article", "web")
print("Insert response: %s", insert_response)
# Query the collection
query_response = rag_client.collection.query("What are the key points of the article?")
print("Query response: %s", query_response)
Tools Module
The Tools module provides access to various AI-powered utilities.
Key Features
- Text generation with different models
- Content categorization
- Image-to-text conversion (OCR)
- Web extraction with structured output
Basic Usage
from wetro import WetroTools
# Initialize Tools client
tools_client = WetroTools(api_key="your_api_key")
# Generate text
generate_response = tools_client.generate_text(
messages=[{"role": "user", "content": "What is a large language model?"}],
model="gpt-4"
)
print("Generate text response: %s", generate_response)
Examples
RAG Examples
Working with Collections
# Create or access a collection
rag_client.collection.get_or_create_collection_id("research_papers")
# Insert documents from different sources
rag_client.collection.insert("https://example.com/research-paper", "web")
rag_client.collection.insert("This is a sample text document about AI.", "text")
Basic Querying
# Simple query
response = rag_client.collection.query("What are the main findings in the research?")
print(response)
Specify Model
# Define Model to get response from the specific model
response = rag_client.collection.query(
"Give me a detailed summary of the article",
model="gpt-3.5-turbo"
)
print(response)
Structured Output with JSON Schema
# Define a JSON schema for structured output
json_schema = [{"point_number": "<int>", "point": "<str>"}]
# Add processing rules
rules = ["Only 5 points", "Strictly return JSON only"]
# Query with structured output requirements
response = rag_client.collection.query(
"What are the key points of the article?",
json_schema,
rules
)
print(response)
Streaming Responses
# Stream responses for long-form content
streaming_response = rag_client.collection.query(
"Give me a detailed summary of the article",
stream=True
)
# Process streaming response
for chunk in streaming_response:
print(chunk.response, end="")
Note: Streaming is not supported with Structured Output with JSON Schema, it's one or the other
Conversational Context
# Create a chat history
chat_history = [
{"role": "user", "content": "What is this collection about?"},
{"role": "system", "content": "It stores research papers on AI technology."}
]
# Continue the conversation with context
chat_response = rag_client.collection.chat(
"Can you explain the latest paper's methodology?",
chat_history
)
print(chat_response)
Tools Examples
Text Generation
# Generate text with a specific model
response = tools_client.generate_text(
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Write a short poem about technology."}
],
model="gpt-4"
)
print(response)
Content Categorization
# Categorize content
categorize_response = tools_client.categorize(
resource="match review: John Cena vs. The Rock.",
type="text",
json_schema='{"label": "string"}',
categories=["wrestling", "entertainment", "sports", "news"]
)
print(categorize_response)
Image to Text (OCR)
# Extract text from an image and answer questions about it
ocr_response = tools_client.image_to_text(
image_url="https://example.com/sample-image.jpg",
request_query="What text is shown in this image?"
)
print(ocr_response)
Web Extraction
# Extract structured data from a website
extract_response = tools_client.extract(
website="https://www.forbes.com/real-time-billionaires/",
json_schema='[{"name": "<name>", "networth": "<networth>"}]'
)
print(extract_response)
Error Handling
The SDK uses standardized error handling. All API calls may raise exceptions derived from WetrocloudError.
from wetro import Wetrocloud, WetrocloudError
client = Wetrocloud(api_key="your_api_key")
try:
response = client.rag.collection.query("What is this article about?")
except WetrocloudError as e:
print(f"Error: {e.status_code} - {e.message}")
# Handle specific error cases
if e.status_code == 401:
print("Authentication failed. Check your API key.")
elif e.status_code == 404:
print("Collection not found. Create a collection first.")
Advanced Usage
Custom Domain
client = Wetrocloud(
api_key="your_api_key",
base_url="custom_url"
)
Configuring Request Timeouts
client = Wetrocloud(
api_key="your_api_key",
timeout=30 # 30 seconds timeout
)
Using with Async Frameworks (Coming Soon)
import asyncio
from wetro import AsyncWetrocloud
async def main():
client = AsyncWetrocloud(api_key="your_api_key")
response = await client.rag.collection.query("What are the key insights?")
return response
result = asyncio.run(main())
API Reference
WetroRAG Methods
collection.get_or_create_collection_id(collection_id)
Sets the current collection ID or creates a new collection.
collection.insert(resource, type)
Inserts a document into the collection.
resource: URL, text content, or file pathtype: "web", "text", "json", or "file"
collection.query(request_query, model=None, json_schema=None, json_schema_rules=None, stream=False)
Queries the collection.
request_query: Natural language querymodel: Optional model name (e.g., "gpt-3.5-turbo", "gpt-4")json_schema: Optional JSON schema for structured outputjson_schema_rules: Optional list of processing rulesstream: Boolean to enable response streaming
collection.chat(message, chat_history=None, model=None, stream=False)
Chat with context from the collection.
message: Current user messagechat_history: List of previous message dictionariesmodel: Optional model namestream: Boolean to enable response streaming
collection.delete_resource(resource_id)
Delete a resource from the collection.
resource_id: Current user message
collection.delete()
Delete the collection.
WetroTools Methods
generate_text(messages, model=None)
Generates text using a specified model.
messages: List of message dictionariesmodel: Model name (e.g., "gpt-3.5-turbo", "gpt-4")
categorize(resource, type, json_schema, categories, prompt)
Categorizes content according to provided categories.
resource: Content to categorizetype: "text", "url", etc.json_schema: Schema for structured outputcategories: List of category optionsprompt: Prompt to instruction or inform the LLM on what and how to perfom the categorization
image_to_text(image_url, request_query=None)
Extracts text from images and optionally answers questions about the content.
image_url: URL of the imagerequest_query: Optional question about the image content
extract(website, json_schema)
Extracts structured data from websites.
website: URL to extract fromjson_schema: Schema defining the data structure to extract
Troubleshooting
Common Issues
-
Authentication Errors
Error: 401 - Invalid API keySolution: Verify your API key is correct and has the necessary permissions.
-
Collection Not Found
Error: 404 - Collection not foundSolution: Use
get_or_create_collection_id()before querying. -
Rate Limiting
Error: 429 - Too many requestsSolution: Implement backoff and retry logic for high-volume operations.
Support
For additional support, please contact support@wetrocloud.com or visit our documentation at https://docs.wetrocloud.com.
Project details
Release history Release notifications | RSS feed
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 wetro-0.1.9.tar.gz.
File metadata
- Download URL: wetro-0.1.9.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28bdc04ea7808f17c58408fa1da1f0e507d5c5e89ac665d8f04cab94c0386923
|
|
| MD5 |
c840e3ca89c5cef1a2e0587329363f6a
|
|
| BLAKE2b-256 |
9c8291ad0660cbc3fdb35979dd7ad41cae6072eadfec93faa05e8dc4e0248d25
|
File details
Details for the file wetro-0.1.9-py3-none-any.whl.
File metadata
- Download URL: wetro-0.1.9-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73b538b6c15305384bc7951809482a1814cf0213fd0da49df88b43dda3ba0aea
|
|
| MD5 |
3312d7b009c151472f7ecc4cf18dea13
|
|
| BLAKE2b-256 |
91e53217f573fd6eeb802eb7545abc2daf5f5e683f543f2f2f0076c6372f16b3
|