indoxrouter 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- indoxRouter/__init__.py +0 -0
- indoxRouter/api_endpoints.py +336 -0
- indoxRouter/client.py +286 -0
- indoxRouter/client_package.py +138 -0
- indoxRouter/init_db.py +71 -0
- indoxRouter/main.py +711 -0
- indoxRouter/migrations/__init__.py +1 -0
- indoxRouter/migrations/env.py +98 -0
- indoxRouter/migrations/versions/__init__.py +1 -0
- indoxRouter/migrations/versions/initial_schema.py +84 -0
- indoxRouter/providers/__init__.py +108 -0
- indoxRouter/providers/ai21.py +268 -0
- indoxRouter/providers/base_provider.py +69 -0
- indoxRouter/providers/claude.py +177 -0
- indoxRouter/providers/cohere.py +171 -0
- indoxRouter/providers/databricks.py +166 -0
- indoxRouter/providers/deepseek.py +166 -0
- indoxRouter/providers/google.py +216 -0
- indoxRouter/providers/llama.py +164 -0
- indoxRouter/providers/meta.py +227 -0
- indoxRouter/providers/mistral.py +182 -0
- indoxRouter/providers/nvidia.py +164 -0
- indoxRouter/providers/openai.py +122 -0
- indoxrouter-0.1.0.dist-info/METADATA +179 -0
- indoxrouter-0.1.0.dist-info/RECORD +27 -0
- indoxrouter-0.1.0.dist-info/WHEEL +5 -0
- indoxrouter-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,138 @@
|
|
1
|
+
"""
|
2
|
+
IndoxRouter Client - A Python client for the IndoxRouter API
|
3
|
+
"""
|
4
|
+
|
5
|
+
import os
|
6
|
+
import requests
|
7
|
+
from typing import Dict, List, Optional, Any, Union
|
8
|
+
|
9
|
+
|
10
|
+
class IndoxRouterClient:
|
11
|
+
"""
|
12
|
+
Client for making API requests to the IndoxRouter API.
|
13
|
+
|
14
|
+
This client allows users to interact with the IndoxRouter API
|
15
|
+
to access multiple LLM providers through a unified interface.
|
16
|
+
"""
|
17
|
+
|
18
|
+
def __init__(self, api_key: str, base_url: str = None):
|
19
|
+
"""
|
20
|
+
Initialize the IndoxRouter client.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
api_key: API key for authentication (generated from the IndoxRouter website)
|
24
|
+
base_url: Base URL for the API (default: https://api.indoxrouter.com)
|
25
|
+
"""
|
26
|
+
self.api_key = api_key
|
27
|
+
self.base_url = base_url or "https://api.indoxrouter.com"
|
28
|
+
self.session = requests.Session()
|
29
|
+
self.session.headers.update(
|
30
|
+
{"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
31
|
+
)
|
32
|
+
|
33
|
+
# Verify the API key by making a test request
|
34
|
+
self._verify_api_key()
|
35
|
+
|
36
|
+
def _verify_api_key(self):
|
37
|
+
"""Verify that the API key is valid by making a test request."""
|
38
|
+
try:
|
39
|
+
response = self.session.get(f"{self.base_url}/api/v1/user")
|
40
|
+
response.raise_for_status()
|
41
|
+
self.user_data = response.json()
|
42
|
+
except requests.exceptions.RequestException as e:
|
43
|
+
raise ValueError(f"Invalid API key or connection error: {str(e)}")
|
44
|
+
|
45
|
+
def generate(
|
46
|
+
self,
|
47
|
+
prompt: str,
|
48
|
+
model: str = None,
|
49
|
+
provider: str = None,
|
50
|
+
temperature: float = 0.7,
|
51
|
+
max_tokens: int = 1000,
|
52
|
+
**kwargs,
|
53
|
+
) -> Dict[str, Any]:
|
54
|
+
"""
|
55
|
+
Generate a response from a model.
|
56
|
+
|
57
|
+
Args:
|
58
|
+
prompt: The prompt to send to the model
|
59
|
+
model: The model to use (e.g., "gpt-4", "claude-3-opus")
|
60
|
+
provider: The provider to use (e.g., "openai", "anthropic")
|
61
|
+
temperature: Controls randomness (0-1)
|
62
|
+
max_tokens: Maximum number of tokens to generate
|
63
|
+
**kwargs: Additional parameters to pass to the API
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
A dictionary containing the response from the API
|
67
|
+
"""
|
68
|
+
if not model and not provider:
|
69
|
+
# Use the default model if none specified
|
70
|
+
model = "gpt-4o-mini"
|
71
|
+
provider = "openai"
|
72
|
+
|
73
|
+
payload = {
|
74
|
+
"prompt": prompt,
|
75
|
+
"temperature": temperature,
|
76
|
+
"max_tokens": max_tokens,
|
77
|
+
**kwargs,
|
78
|
+
}
|
79
|
+
|
80
|
+
if model:
|
81
|
+
payload["model"] = model
|
82
|
+
if provider:
|
83
|
+
payload["provider"] = provider
|
84
|
+
|
85
|
+
response = self.session.post(f"{self.base_url}/api/v1/generate", json=payload)
|
86
|
+
response.raise_for_status()
|
87
|
+
return response.json()
|
88
|
+
|
89
|
+
def list_models(self, provider: Optional[str] = None) -> List[Dict[str, Any]]:
|
90
|
+
"""
|
91
|
+
List available models.
|
92
|
+
|
93
|
+
Args:
|
94
|
+
provider: Filter models by provider
|
95
|
+
|
96
|
+
Returns:
|
97
|
+
A list of available models
|
98
|
+
"""
|
99
|
+
url = f"{self.base_url}/api/v1/models"
|
100
|
+
if provider:
|
101
|
+
url += f"?provider={provider}"
|
102
|
+
|
103
|
+
response = self.session.get(url)
|
104
|
+
response.raise_for_status()
|
105
|
+
return response.json()
|
106
|
+
|
107
|
+
def list_providers(self) -> List[Dict[str, Any]]:
|
108
|
+
"""
|
109
|
+
List available providers.
|
110
|
+
|
111
|
+
Returns:
|
112
|
+
A list of available providers
|
113
|
+
"""
|
114
|
+
response = self.session.get(f"{self.base_url}/api/v1/providers")
|
115
|
+
response.raise_for_status()
|
116
|
+
return response.json()
|
117
|
+
|
118
|
+
def get_balance(self) -> Dict[str, Any]:
|
119
|
+
"""
|
120
|
+
Get the user's current balance.
|
121
|
+
|
122
|
+
Returns:
|
123
|
+
A dictionary containing the user's balance information
|
124
|
+
"""
|
125
|
+
response = self.session.get(f"{self.base_url}/api/v1/user/balance")
|
126
|
+
response.raise_for_status()
|
127
|
+
return response.json()
|
128
|
+
|
129
|
+
def get_user_info(self) -> Dict[str, Any]:
|
130
|
+
"""
|
131
|
+
Get information about the authenticated user.
|
132
|
+
|
133
|
+
Returns:
|
134
|
+
A dictionary containing user information
|
135
|
+
"""
|
136
|
+
response = self.session.get(f"{self.base_url}/api/v1/user")
|
137
|
+
response.raise_for_status()
|
138
|
+
return response.json()
|
indoxRouter/init_db.py
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
Initialize the database for IndoxRouter.
|
4
|
+
|
5
|
+
This script creates the database tables and an admin user.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import os
|
9
|
+
import sys
|
10
|
+
import logging
|
11
|
+
import argparse
|
12
|
+
from pathlib import Path
|
13
|
+
|
14
|
+
# Add the parent directory to sys.path
|
15
|
+
sys.path.append(str(Path(__file__).parent.parent))
|
16
|
+
|
17
|
+
# Configure logging
|
18
|
+
logging.basicConfig(
|
19
|
+
level=logging.INFO,
|
20
|
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
21
|
+
handlers=[
|
22
|
+
logging.StreamHandler(),
|
23
|
+
logging.FileHandler(os.path.join("logs", "init_db.log"), mode="a"),
|
24
|
+
],
|
25
|
+
)
|
26
|
+
logger = logging.getLogger(__name__)
|
27
|
+
|
28
|
+
|
29
|
+
def main():
|
30
|
+
"""Initialize the database."""
|
31
|
+
parser = argparse.ArgumentParser(description="Initialize the IndoxRouter database")
|
32
|
+
parser.add_argument(
|
33
|
+
"--force", action="store_true", help="Force initialization even if tables exist"
|
34
|
+
)
|
35
|
+
parser.add_argument("--admin-email", help="Admin user email")
|
36
|
+
parser.add_argument("--admin-password", help="Admin user password")
|
37
|
+
args = parser.parse_args()
|
38
|
+
|
39
|
+
try:
|
40
|
+
# Ensure logs directory exists
|
41
|
+
os.makedirs("logs", exist_ok=True)
|
42
|
+
|
43
|
+
# Import here to avoid circular imports
|
44
|
+
from indoxRouter.utils.migrations import create_tables, create_admin_user
|
45
|
+
|
46
|
+
# Create the tables
|
47
|
+
logger.info("Creating database tables...")
|
48
|
+
create_tables(force=args.force)
|
49
|
+
|
50
|
+
# Create the admin user
|
51
|
+
admin_email = args.admin_email or os.environ.get(
|
52
|
+
"ADMIN_EMAIL", "admin@example.com"
|
53
|
+
)
|
54
|
+
admin_password = args.admin_password or os.environ.get(
|
55
|
+
"ADMIN_PASSWORD", "admin"
|
56
|
+
)
|
57
|
+
|
58
|
+
logger.info(f"Creating admin user with email: {admin_email}")
|
59
|
+
create_admin_user(email=admin_email, password=admin_password)
|
60
|
+
|
61
|
+
logger.info("Database initialization complete.")
|
62
|
+
logger.info("You can now log in with the following credentials:")
|
63
|
+
logger.info(f"Email: {admin_email}")
|
64
|
+
logger.info(f"Password: {admin_password}")
|
65
|
+
except Exception as e:
|
66
|
+
logger.error(f"Error initializing database: {e}", exc_info=True)
|
67
|
+
sys.exit(1)
|
68
|
+
|
69
|
+
|
70
|
+
if __name__ == "__main__":
|
71
|
+
main()
|