KISS AI Stack - Python Client SDK
The KISS AI Stack Client provides an easy-to-use interface for interacting with the KISS AI Stack Server stub, supporting RESTful and WebSocket APIs to manage Stack session lifecycle and execute tasks.
Features
- REST client for session management, query execution, and document storage.
- WebSocket client for real-time interactions with the Stack’s server session.
Getting Started
Nota Bene:
It is recommended to use this client in a proxy service for better security.
Installation
- Install the
kiss-ai-stack-client
package:pip install kiss-ai-stack-client~=0.1.0a6
- Initialize the client:
- REST API client
from kiss_ai_stack_client import RestEvent
# host name without mentioning protocol, i.e. example.com, localhost:8080
# secure_protocol, whether to use https or http
client = RestEvent(hostname="your-server-hostname", secure_protocol=True)
- WebSocket-based client
from kiss_ai_stack_client import WebSocketEvent
# host name without mentioning protocol, i.e. example.com, localhost:8080
# secure_protocol, whether to use wss or ws
client = WebSocketEvent(hostname="your-server-hostname", secure_protocol=True)
Usage
1. Authorize a Stack Session
Create or refresh a Stack session:
To authorize the session, if you have saved a previous client_id
and a client_secret
, send them to get a new access token. Only persistent
scope supports this. temporary
scope will deactivate the client upon lifecycle ending.
Just send the scope
only to generate a new client and keep the client_id and client_secret saved for persistent
sessions.
session = await client.authorize_stack(scope="temporary") # scopes - 'temporary', 'persistent'
# or, get a new access token for a previous 'persistent session'
session = await client.authorize_stack(client_id="your-client-id", client_secret="your-client-secret")
2. Bootstrap the Stack
Initialize the Stack session for task execution:
This step is a must to start the Stack session.
response = await client.bootstrap_stack(data="Hello, Stack!")
3. Generate an Answer
Send a query and receive the Stack’s response:
response = await client.generate_answer(data="What is the weather today?")
4. Store Documents
Upload files with optional metadata for storage:
files = ["path/to/document1.txt", "path/to/document2.pdf"]
metadata = {"category": "example"}
response = await client.store_data(files=files, metadata=metadata)
response = await client.generate_answer(data='Give me a summary of example documents')
5. Destroy the Stack Session
Close the current session (will clean up stored documents in a temporary session if it has):
response = await client.destroy_stack(data="Goodbye!")