SECRET AI SDK

This page introduces Secret AI SDK, provides guidance and examples how to use Secret AI SDK.

Secret AI SDK

PyPI version Python versions License

The Secret AI SDK provides a comprehensive Python interface for accessing Secret Network's confidential AI models, including text generation, speech-to-text (STT), and text-to-speech (TTS) capabilities. Built with enterprise-grade reliability and privacy-preserving features.

Overview

The Secret AI SDK is a Python library that enables secure, private access to Secret Network's confidential AI infrastructure. The SDK provides intuitive APIs for text-based language models, voice processing, and multimodal AI capabilities while ensuring all computations remain confidential through Secret's privacy-preserving technology.

Core Features

AI Capabilities

  • Text Generation: Access to Secret Confidential AI language models with streaming support

  • Voice Processing: Unified STT and TTS functionality through the VoiceSecret class

  • Multimodal Support: Handle text, audio, and voice interactions seamlessly

  • Ollama API Compatibility: Full support for OpenAI-compatible endpoints

Enterprise-Grade Reliability

  • Enhanced Error Handling: Comprehensive exception hierarchy with detailed error context

  • Automatic Retry Logic: Configurable exponential backoff for network resilience

  • Timeout Management: Customizable request and connection timeout controls

  • Response Validation: Built-in validation for API response integrity

  • Concurrency Support: Handle multiple concurrent requests efficiently

Developer Experience

  • Clean Pythonic Interface: Intuitive APIs following Python best practices

  • Flexible Authentication: API key-based authentication with environment variable support

  • Comprehensive Logging: Detailed logging for debugging and monitoring

  • Context Manager Support: Proper resource management with context managers

Architecture

Core Components

The SDK consists of several key modules:

  • secret.py: Main client for accessing Secret Network smart contracts

  • secret_ai.py: Chat interface built on LangChain for text generation

  • voice_secret.py: Unified voice processing (STT/TTS) interface

  • _enhanced_client.py: Enhanced clients with retry logic and error handling

  • _config.py: Configuration management and environment variables

  • secret_ai_ex.py: Custom exception classes for comprehensive error handling

  • _retry.py: Retry logic with exponential backoff

SDK Structure

Quick Start

Text Generation with ChatSecret

Voice Processing with VoiceSecret

Network Configuration

For custom Secret Network node configuration:

Error Handling & Debugging

Exception Hierarchy

Logging Configuration

Enable detailed logging for debugging:

Retry Logic Details

The SDK implements intelligent retry logic with exponential backoff:

  • Retryable Errors: Network timeouts, connection errors, temporary server errors

  • Non-Retryable Errors: Authentication failures, invalid input, permanent server errors

  • Backoff Strategy: Exponential with jitter to prevent thundering herd

  • Configuration: All retry parameters are configurable via environment variables

Examples Repository

For additional examples and use cases, refer to the provided example files:

  • example.py: Comprehensive streaming implementation with custom handlers

  • voice_example.py: Voice processing examples with health checks and error handling

  • test_secret_ai.py: Basic connectivity and functionality tests

Contributing

Contributions are welcome! Please submit pull requests to the GitHub repository.

License

The Secret AI SDK is licensed under the MIT License.


This documentation covers version 0.1.5 of the Secret AI SDK. For the latest updates and features, please check the PyPI package page.

Last updated

Was this helpful?