Python SDK
Ask Sage Python Client
A powerful, easy-to-use Python library for seamless Ask Sage API integration
Table of Contents
Overview
Available Methods
The client exposes methods covering models, queries, training, datasets, plugins/agents, and usage tracking:
| Method | Description |
|---|---|
get_models() | Retrieve all available AI models |
query() | Send queries to AI models with full customization |
query_with_file() | Query with file attachments for context |
train() | Add content to your knowledge base |
train_with_file() | Train using file uploads |
file() | Upload and process files |
add_dataset() | Create new datasets |
delete_dataset() | Remove datasets |
assign_dataset() | Assign datasets to users |
get_datasets() | List all available datasets |
get_personas() | Retrieve available AI personas |
get_plugins() | List available plugins/agents |
query_plugin() | Execute queries using specific plugins |
execute_plugin() | Run plugins with custom content |
follow_up_questions() | Generate contextual follow-up questions |
tokenizer() | Calculate token counts for content |
get_user_logs() | Retrieve user activity logs |
get_user_logins() | Get user login history |
count_monthly_tokens() | Track monthly token usage |
count_monthly_teach_tokens() | Monitor training token consumption |
Example Notebook
Quick Start Guide
Install the Ask Sage Python Client using pip:
pip install asksageclient
Documentation: Full package reference is available on PyPI.
Load credentials and create an Ask Sage client instance:
import json
from asksageclient import AskSageClient
# Load credentials from file
def load_credentials(filename):
"""Load API credentials from JSON file."""
try:
with open(filename) as file:
return json.load(file)
except FileNotFoundError:
raise FileNotFoundError(f"Credentials file '{filename}' not found.")
except json.JSONDecodeError:
raise ValueError("Invalid JSON in credentials file.")
# Initialize credentials
credentials = load_credentials('credentials.json')
api_key = credentials['credentials']['api_key']
email = credentials['credentials']['Ask_sage_user_info']['username']
# Create Ask Sage client
client = AskSageClient(
email=email,
api_key=api_key,
user_base_url='https://api.asksage.ai/user', # Optional: User API base URL
server_base_url='https://api.asksage.ai/server' # Optional: Server API base URL
)
print("Ask Sage client initialized successfully!")