SHADAI Client
Project description
SHADAI Intelligence Client
A Python client for interacting with the SHADAI API. This client provides a simple interface for document processing, querying, and session management.
Installation
pip install shadai
Requirements
- Python >= 3.12
- Environment Variables:
SHADAI_API_KEY: Your SHADAI API key
Quick Start
import asyncio
import os
from typing import Dict
from shadai.core.agents import ToolAgent
from shadai.core.session import Session
input_dir = os.path.join(os.path.dirname(__file__), "data")
def get_constitutional_article(article_id: str) -> str:
articles: Dict[str, Dict[str, str]] = {
"1": {
"title": "Primera Enmienda",
"description": "Libertad de expresión, religión, prensa y reunión",
"content": "El Congreso no hará ley alguna con respecto al establecimiento de religión, ni prohibiendo la libre práctica de la misma; ni limitando la libertad de expresión, ni de prensa; ni el derecho del pueblo a reunirse pacíficamente.",
},
"2": {
"title": "Segunda Enmienda",
"description": "Derecho a portar armas",
"content": "Siendo necesaria una milicia bien ordenada para la seguridad de un Estado libre, no se violará el derecho del pueblo a poseer y portar armas.",
},
}
if article_id not in articles:
return "Artículo no encontrado"
article = articles[article_id]
return f"Título: {article['title']}\nDescripción: {article['description']}\nContenido: {article['content']}"
async def main():
async with Session(type="standard", delete_session=True) as session:
await session.ingest(input_dir=input_dir)
await session.query(
query="¿De qué habla la quinta enmienda?", display_in_console=True
)
await session.summarize(display_in_console=True)
await session.create_article(
topic="Enmiendas de la constitución y su impacto social",
display_in_console=True,
)
agent = ToolAgent(
session=session,
prompt="""
Analiza la relación entre la Primera Enmienda y las empresas digitales:
Enmienda Constitucional:
{function_output}
Contexto de documentos:
{summary}
Considerando la Primera Enmienda y el contexto histórico, analiza:
1. Cómo se aplican los principios de libertad de expresión en el entorno digital
2. Desafíos y oportunidades para las empresas digitales en relación con estos derechos
3. Recomendaciones para equilibrar la innovación tecnológica con los derechos constitucionales
""",
use_summary=True,
function=get_constitutional_article,
)
await agent.call(article_id="1")
if __name__ == "__main__":
asyncio.run(main())
Features
- Asynchronous API interactions
- Automatic session management
- File ingestion with progress tracking
- Interactive query interface
- Robust error handling and retries
- Rich console output
Session Configuration
| Parameter | Type | Description | Default |
|---|---|---|---|
| type | str | Processing type ("light", "standard", "deep") | "standard" |
| llm_model | str | Language model to use | None |
| llm_temperature | float | Model temperature | None |
| llm_max_tokens | int | Maximum tokens for response | None |
| query_mode | str | Query processing mode | None |
| language | str | Response language | None |
| delete_session | bool | Auto-delete session on exit | True |
Error Handling
The client includes comprehensive error handling for:
- Configuration errors
- API communication issues
- File processing problems
- Session management failures
Author
SHADAI GROUP jaisir@shadai.ai
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
shadai-0.1.15.tar.gz
(40.8 kB
view details)
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
shadai-0.1.15-py3-none-any.whl
(13.8 kB
view details)
File details
Details for the file shadai-0.1.15.tar.gz.
File metadata
- Download URL: shadai-0.1.15.tar.gz
- Upload date:
- Size: 40.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a97c52a56438d6ff7fef690da2837c7488dca55b25f88dc68a5363f8a922bd72
|
|
| MD5 |
23eccd7592d0b4f7034850ed39c188a0
|
|
| BLAKE2b-256 |
0932a623b439e9b2d9c81a517b04e69cc68684a41d2567a0af0dcfe5a510d52e
|
File details
Details for the file shadai-0.1.15-py3-none-any.whl.
File metadata
- Download URL: shadai-0.1.15-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15eb33c475d2405b8b66efde58b73bc449e87afb01fa30df4dbde0e7c35575a4
|
|
| MD5 |
ef30e210cd0ca2072314213dfbb986df
|
|
| BLAKE2b-256 |
8b9649042b194e9a31f0fd4f6ca8f2d8c14e546eb86588c207aeb6a1fff7a87d
|