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.12.tar.gz
(40.7 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.12-py3-none-any.whl
(13.7 kB
view details)
File details
Details for the file shadai-0.1.12.tar.gz.
File metadata
- Download URL: shadai-0.1.12.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b00d4a2ede3d2138ea4a2ba6f0082af74a8e8e0b10e25417e8a191a733177ba
|
|
| MD5 |
e6767390dc9eee8fc825ba7b319c4e88
|
|
| BLAKE2b-256 |
6e771f584ba468c7266c9f85ee6e3d6382e2ae02c56d7fde0df4b17081985b2b
|
File details
Details for the file shadai-0.1.12-py3-none-any.whl.
File metadata
- Download URL: shadai-0.1.12-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8030a1cd1b8db1f7bd69bdcca072ab14be0b45e9e38f6b1a9042b22d810899c9
|
|
| MD5 |
30dd23a5d6b71391052e752aa6081de2
|
|
| BLAKE2b-256 |
679787395606133a18a789e37e87e8a1a65ae4a33ba3da919ef5aef608967d86
|