SHADAI Client
Project description
Shadai Client - Official Python SDK
Beautiful, Pythonic client for Shadai AI services. Query your knowledge base, orchestrate custom tools with intelligent agents, and more with an intuitive, production-ready API.
๐ What's New in v0.1.29
- ๐ง Memory enabled by default - All tools now use conversation memory by default for better context continuity
- ๐ฌ Chat history management - New methods to retrieve and clear session history with pagination
- ๐ Enhanced documentation - Updated examples and API reference with new features
โจ Features
- ๐ Easy to use - Clean, intuitive API design with one-step async patterns
- โก Async streaming - Real-time streaming responses for all tools
- ๐ ๏ธ Multiple tools - Query, summarize, search, engine, and intelligent agent
- ๐ค Intelligent agent - Automatic plan โ execute โ synthesize workflow
- ๐ง Conversation memory - Built-in memory enabled by default for context continuity
- ๐ฌ Chat history management - Get and clear session history with pagination
- ๐ Type-safe - Full type hints and Pydantic models for better IDE support
- ๐ฆ Minimal dependencies - Only requires
aiohttpandpydantic - ๐ฏ Production-ready - Comprehensive error handling
๐ฆ Installation
pip install shadai-client
Or install from source:
cd client
pip install -e .
๐ Quick Start
import asyncio
from shadai import Shadai
async def main():
# Create session and query
async with Shadai(name="my-session") as shadai:
# Ingest documents
await shadai.ingest(folder_path="./documents")
# Query knowledge base
async for chunk in shadai.query("What is machine learning?"):
print(chunk, end="", flush=True)
asyncio.run(main())
๐ Usage Examples
Knowledge Base Query
Query your uploaded documents using RAG (Retrieval-Augmented Generation):
async with Shadai(name="research") as shadai:
# Ingest documents
await shadai.ingest(folder_path="./documents")
# Ask questions about your documents
async for chunk in shadai.query("What are the key findings?"):
print(chunk, end="", flush=True)
# Memory is enabled by default for context continuity
async for chunk in shadai.query("Tell me more about that"):
print(chunk, end="", flush=True)
# Disable memory if needed
async for chunk in shadai.query("Independent question", use_memory=False):
print(chunk, end="", flush=True)
Document Summarization
Generate comprehensive summaries of all documents in a session:
async with Shadai(name="research") as shadai:
await shadai.ingest(folder_path="./documents")
async for chunk in shadai.summarize():
print(chunk, end="", flush=True)
Web Search
Search the internet for current information:
async with Shadai(name="news") as shadai:
async for chunk in shadai.web_search("Latest AI developments 2024"):
print(chunk, end="", flush=True)
Chat History Management
Retrieve and manage conversation history for sessions:
async with Shadai(name="chat") as shadai:
# Get chat history with pagination
history = await shadai.get_session_history(
page=1,
page_size=5 # Default: 5, Max: 10
)
print(f"Total messages: {history['count']}")
for message in history["results"]:
print(f"{message['role']}: {message['content']}")
# Clear all chat history
result = await shadai.clear_session_history()
print(result["message"]) # "Session history cleared successfully"
Unified Engine
Orchestrate multiple tools for comprehensive answers:
async with Shadai(name="analysis") as shadai:
await shadai.ingest(folder_path="./documents")
async for chunk in shadai.engine(
prompt="Compare my docs with current trends",
use_knowledge_base=True,
use_web_search=True
):
print(chunk, end="", flush=True)
Intelligent Agent
Orchestrate plan โ execute โ synthesize workflow with custom tools. The planner automatically infers tool arguments from your prompt!
from shadai import Shadai, tool
# Define tools using @tool decorator
@tool
def search_database(query: str, limit: int = 10) -> str:
"""Search database for user information.
Args:
query: Search query string
limit: Maximum number of results
"""
# Your implementation
return "Search results..."
@tool
def generate_report(data: str, format: str = "text") -> str:
"""Generate a formatted report.
Args:
data: Data to include in report
format: Report format (text, pdf, etc.)
"""
# Your implementation
return "Generated report..."
# Agent automatically infers arguments from your prompt!
async with Shadai(name="agent") as shadai:
async for chunk in shadai.agent(
prompt="Find the top 5 users and create a PDF report",
tools=[search_database, generate_report]
):
print(chunk, end="", flush=True)
The agent automatically:
- Plans which tools to use based on your prompt
- Infers the appropriate arguments for each tool from your prompt
- Executes the selected tools locally with inferred arguments
- Synthesizes all outputs into a unified, coherent answer
๐ง Configuration
Environment Variables
export SHADAI_API_KEY="your-api-key"
export SHADAI_BASE_URL="http://localhost" # Optional
Client Initialization
# Named session (persistent)
async with Shadai(name="my-project") as shadai:
await shadai.ingest(folder_path="./docs")
# Temporal session (auto-deleted)
async with Shadai(temporal=True) as shadai:
async for chunk in shadai.query("Quick question"):
print(chunk, end="")
# Custom configuration
async with Shadai(
name="custom",
api_key="your-api-key",
base_url="https://api.shadai.com",
timeout=60 # seconds
) as shadai:
pass
๐ ๏ธ Available Tools
| Tool | Description | Streaming |
|---|---|---|
query() |
Query knowledge base with RAG | โ |
summarize() |
Summarize all session documents | โ |
web_search() |
Search web for current information | โ |
engine() |
Unified multi-tool orchestration | โ |
agent() |
Intelligent agent (plan โ execute โ synthesize) | โ |
get_session_history() |
Retrieve chat history with pagination | โ |
clear_session_history() |
Clear all messages in a session | โ |
๐ API Reference
Shadai
Main entry point for the client.
Shadai(
name: str = None,
temporal: bool = False,
api_key: str = None,
base_url: str = "http://localhost",
timeout: int = 30
)
Methods:
ingest(folder_path)โDict- Ingest documents from folderquery(query, use_memory=True)โAsyncIterator[str]- Query knowledge basesummarize(use_memory=True)โAsyncIterator[str]- Summarize documentsweb_search(prompt, use_web_search=True, use_memory=True)โAsyncIterator[str]- Search webengine(prompt, **options)โAsyncIterator[str]- Unified engineagent(prompt, tools)โAsyncIterator[str]- Intelligent agentget_session_history(page=1, page_size=5)โDict[str, Any]- Get chat historyclear_session_history()โDict[str, str]- Clear chat history
query()
Query your knowledge base with streaming responses. Memory enabled by default.
async with Shadai(name="docs") as shadai:
async for chunk in shadai.query("What is AI?", use_memory=True):
print(chunk, end="")
summarize()
Summarize all documents in a session. Memory enabled by default.
async with Shadai(name="docs") as shadai:
async for chunk in shadai.summarize(use_memory=True):
print(chunk, end="")
web_search()
Search the web for current information. Memory enabled by default.
async with Shadai(name="search") as shadai:
async for chunk in shadai.web_search("Latest AI news"):
print(chunk, end="")
engine()
Unified engine with multiple tool capabilities. Memory enabled by default.
async with Shadai(name="engine") as shadai:
async for chunk in shadai.engine(
prompt="Analyze my documents",
use_knowledge_base=True,
use_web_search=True
):
print(chunk, end="")
get_session_history()
Retrieve chat history with pagination support.
async with Shadai(name="chat") as shadai:
history = await shadai.get_session_history(page=1, page_size=5)
# Response includes: count, next, previous, results
for msg in history["results"]:
print(f"{msg['role']}: {msg['content']}")
clear_session_history()
Clear all messages in a session.
async with Shadai(name="chat") as shadai:
result = await shadai.clear_session_history()
# Returns: {"message": "Session history cleared successfully"}
agent()
Intelligent agent that orchestrates custom tools.
from shadai import tool
@tool
def my_tool(param: str) -> str:
"""Tool description."""
return "result"
async with Shadai(name="agent") as shadai:
async for chunk in shadai.agent(
prompt="Execute task",
tools=[my_tool]
):
print(chunk, end="")
๐จ Error Handling
from shadai import (
Shadai,
AuthenticationError,
ConnectionError,
ServerError
)
try:
shadai = Shadai(api_key="invalid-key")
await shadai.health()
except AuthenticationError:
print("Invalid API key")
except ConnectionError:
print("Cannot connect to server")
except ServerError as e:
print(f"Server error: {e}")
๐ Examples
Check the examples/ directory for complete examples:
query_example.py- Knowledge base queriessummary_example.py- Document summarizationwebsearch_example.py- Web searchagent_example.py- Intelligent agent workflowagent_synthesis_example.py- Advanced synthesis with multiple data sourcescomplete_workflow.py- Full agent workflow with multiple examples
Run examples:
cd client/
python examples/query_example.py
python examples/summary_example.py
python examples/websearch_example.py
python examples/agent_example.py
python examples/agent_synthesis_example.py
python examples/complete_workflow.py
๐ Security
- Always use environment variables for API keys
- Never commit API keys to version control
- Use HTTPS in production (
base_url="https://...")
๐ค Contributing
Contributions welcome! Please read our contributing guidelines.
๐ License
MIT License - see LICENSE file for details.
๐ Links
- Documentation: https://docs.shadai.com
- GitHub: https://github.com/shadai/shadai-client
- Issues: https://github.com/shadai/shadai-client/issues
๐ก Support
- ๐ง Email: support@shadai.com
- ๐ฌ Discord: https://discord.gg/shadai
- ๐ Docs: https://docs.shadai.com
Made with โค๏ธ by the Shadai Team
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 shadai-0.1.31.tar.gz.
File metadata
- Download URL: shadai-0.1.31.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb863eb7f0c0e2e5905adf5993c1e313c847d3db4b96fe226ad6898f535c8c90
|
|
| MD5 |
5c5b2d39bb900b11a6a9ff7ea497281c
|
|
| BLAKE2b-256 |
9b900fda916ae115f36c563f8e20a7ab3a0077c7a24595da4ce4dc5d562974db
|
File details
Details for the file shadai-0.1.31-py3-none-any.whl.
File metadata
- Download URL: shadai-0.1.31-py3-none-any.whl
- Upload date:
- Size: 29.6 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 |
4586abd084d427ff1c42d12070271f271a381ec19ea948986e918476f0fc3581
|
|
| MD5 |
da6baf807f31c010f180de16fd0fb2ce
|
|
| BLAKE2b-256 |
2c903a207dbf476c10ad0432cd7037a0155710d171ec79333bd4c54e470b2480
|