A powerful, OpenAI-compatible Python SDK for TNSA NGen3 Pro and Lite Models
Project description
TNSA API Python Client
A powerful, OpenAI-compatible Python SDK for TNSA NGen3 Pro and Lite Models.
Features
- 🚀 OpenAI-Compatible API - Familiar interface for easy migration
- ⚡ Async & Sync Support - Both synchronous and asynchronous clients
- 🌊 Streaming Responses - Real-time token streaming for interactive applications
- 🔧 Comprehensive Error Handling - Robust error handling with retry logic
- 📊 Usage Tracking - Built-in token counting and cost estimation
- 💬 Conversation Management - Automatic chat history and context management
- 🔒 Secure Authentication - API key management with environment variable support
- 📝 Type Safety - Full type hints for better IDE support
- 🎯 Framework Integration - Works seamlessly with FastAPI, Django, and more
Installation
pip install tnsa-api
Quick Start
from tnsa_api_v2 import TNSA
# Initialize the client
client = TNSA(api_key="your-api-key")
# List available models
models = client.models.list()
print("Available models:", [model.id for model in models])
# Create a chat completion
response = client.chat.completions.create(
model="NGen3.9-Pro",
messages=[
{"role": "user", "content": "Hello, how are you?"}
]
)
print(response.choices[0].message.content)
Streaming Example
# Streaming responses
stream = client.chat.completions.create(
model="NGen3.9-Lite",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
Async Usage
import asyncio
from tnsa_api_v2 import AsyncTNSA
async def main():
client = AsyncTNSA(api_key="your-api-key")
response = await client.chat.completions.acreate(
model="NGen3.9-Pro",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
asyncio.run(main())
Configuration
The client can be configured using environment variables, configuration files, or direct parameters:
Environment Variables
export TNSA_API_KEY="your-api-key"
export TNSA_BASE_URL="https://api.tnsaai.com"
export TNSA_TIMEOUT=30.0
Configuration File (config.yaml)
api_key: "your-api-key"
base_url: "https://api.tnsaai.com"
timeout: 30.0
max_retries: 3
default_model: "NGen3.9-Pro"
Direct Parameters
client = TNSA(
api_key="your-api-key",
base_url="https://api.tnsaai.com",
timeout=30.0,
max_retries=3
)
Available Models
- NGen3.9-Pro - High-performance model for complex tasks
- NGen3.9-Lite - Fast, efficient model for general use
- NGen3-7B-0625 - Specialized model variant
- Farmvaidya-Bot - Agricultural domain-specific model
Error Handling
from tnsa_api_v2 import TNSAError, RateLimitError, AuthenticationError
try:
response = client.chat.completions.create(
model="NGen3.9-Pro",
messages=[{"role": "user", "content": "Hello!"}]
)
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded")
except TNSAError as e:
print(f"API error: {e}")
Documentation
For detailed documentation, examples, and API reference, visit: https://docs.tnsaai.com
Support
- 📧 Email: info@tnsaai.com
- 🐛 Issues: GitHub Issues
- 📖 Documentation: https://docs.tnsaai.com
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file tnsa_api-1.0.1.tar.gz.
File metadata
- Download URL: tnsa_api-1.0.1.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b534810686609c3d35a8363dc6a29e33533c8710a5adcd21b9dc73cb863f234c
|
|
| MD5 |
749c3106215586f14f83a245a3ae4e34
|
|
| BLAKE2b-256 |
67fc5ffe1479aa4e9e4f6b41d6b6ddf14140714c9e6cb447ee3f235ec6580b0f
|
File details
Details for the file tnsa_api-1.0.1-py3-none-any.whl.
File metadata
- Download URL: tnsa_api-1.0.1-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a56ab0109f2e63795a787a286538435b80e2890ffa6ab2df846fa44470c4afd
|
|
| MD5 |
e7835b775b7b7a417fe17c460aa56816
|
|
| BLAKE2b-256 |
82c7d72ca7e3238c747f112558d82584f6438e145fccf68a09bf0780f4c3b187
|