indoxrouter 0.1.0__tar.gz → 0.1.2__tar.gz
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-0.1.2/LICENSE +21 -0
- indoxrouter-0.1.2/PKG-INFO +259 -0
- indoxrouter-0.1.2/README.md +209 -0
- indoxrouter-0.1.2/indoxRouter/__init__.py +83 -0
- indoxrouter-0.1.2/indoxRouter/client.py +632 -0
- indoxrouter-0.1.2/indoxRouter/client_resourses/__init__.py +20 -0
- indoxrouter-0.1.2/indoxRouter/client_resourses/base.py +67 -0
- indoxrouter-0.1.2/indoxRouter/client_resourses/chat.py +144 -0
- indoxrouter-0.1.2/indoxRouter/client_resourses/completion.py +138 -0
- indoxrouter-0.1.2/indoxRouter/client_resourses/embedding.py +83 -0
- indoxrouter-0.1.2/indoxRouter/client_resourses/image.py +116 -0
- indoxrouter-0.1.2/indoxRouter/client_resourses/models.py +114 -0
- indoxrouter-0.1.2/indoxRouter/config.py +151 -0
- indoxrouter-0.1.2/indoxRouter/constants/__init__.py +81 -0
- indoxrouter-0.1.2/indoxRouter/exceptions/__init__.py +70 -0
- indoxrouter-0.1.2/indoxRouter/models/__init__.py +111 -0
- indoxrouter-0.1.2/indoxRouter/providers/__init__.py +108 -0
- indoxrouter-0.1.2/indoxRouter/providers/ai21labs.json +128 -0
- indoxrouter-0.1.2/indoxRouter/providers/base_provider.py +101 -0
- indoxrouter-0.1.2/indoxRouter/providers/claude.json +164 -0
- indoxrouter-0.1.2/indoxRouter/providers/cohere.json +116 -0
- indoxrouter-0.1.2/indoxRouter/providers/databricks.json +110 -0
- indoxrouter-0.1.2/indoxRouter/providers/deepseek.json +110 -0
- indoxrouter-0.1.2/indoxRouter/providers/google.json +128 -0
- indoxrouter-0.1.2/indoxRouter/providers/meta.json +128 -0
- indoxrouter-0.1.2/indoxRouter/providers/mistral.json +146 -0
- indoxrouter-0.1.2/indoxRouter/providers/nvidia.json +110 -0
- indoxrouter-0.1.2/indoxRouter/providers/openai.json +308 -0
- indoxrouter-0.1.2/indoxRouter/providers/openai.py +521 -0
- indoxrouter-0.1.2/indoxRouter/providers/qwen.json +110 -0
- indoxrouter-0.1.2/indoxRouter/utils/__init__.py +240 -0
- indoxrouter-0.1.2/indoxRouter.egg-info/PKG-INFO +259 -0
- indoxrouter-0.1.2/indoxRouter.egg-info/SOURCES.txt +42 -0
- indoxrouter-0.1.2/indoxRouter.egg-info/requires.txt +24 -0
- indoxrouter-0.1.2/setup.py +63 -0
- indoxrouter-0.1.2/tests/test_client.py +136 -0
- indoxrouter-0.1.0/PKG-INFO +0 -179
- indoxrouter-0.1.0/README.md +0 -155
- indoxrouter-0.1.0/indoxRouter/__init__.py +0 -0
- indoxrouter-0.1.0/indoxRouter/api_endpoints.py +0 -336
- indoxrouter-0.1.0/indoxRouter/client.py +0 -286
- indoxrouter-0.1.0/indoxRouter/client_package.py +0 -138
- indoxrouter-0.1.0/indoxRouter/init_db.py +0 -71
- indoxrouter-0.1.0/indoxRouter/main.py +0 -711
- indoxrouter-0.1.0/indoxRouter/migrations/__init__.py +0 -1
- indoxrouter-0.1.0/indoxRouter/migrations/env.py +0 -98
- indoxrouter-0.1.0/indoxRouter/migrations/versions/__init__.py +0 -1
- indoxrouter-0.1.0/indoxRouter/migrations/versions/initial_schema.py +0 -84
- indoxrouter-0.1.0/indoxRouter/providers/__init__.py +0 -108
- indoxrouter-0.1.0/indoxRouter/providers/ai21.py +0 -268
- indoxrouter-0.1.0/indoxRouter/providers/base_provider.py +0 -69
- indoxrouter-0.1.0/indoxRouter/providers/claude.py +0 -177
- indoxrouter-0.1.0/indoxRouter/providers/cohere.py +0 -171
- indoxrouter-0.1.0/indoxRouter/providers/databricks.py +0 -166
- indoxrouter-0.1.0/indoxRouter/providers/deepseek.py +0 -166
- indoxrouter-0.1.0/indoxRouter/providers/google.py +0 -216
- indoxrouter-0.1.0/indoxRouter/providers/llama.py +0 -164
- indoxrouter-0.1.0/indoxRouter/providers/meta.py +0 -227
- indoxrouter-0.1.0/indoxRouter/providers/mistral.py +0 -182
- indoxrouter-0.1.0/indoxRouter/providers/nvidia.py +0 -164
- indoxrouter-0.1.0/indoxRouter/providers/openai.py +0 -122
- indoxrouter-0.1.0/indoxrouter.egg-info/PKG-INFO +0 -179
- indoxrouter-0.1.0/indoxrouter.egg-info/SOURCES.txt +0 -30
- indoxrouter-0.1.0/indoxrouter.egg-info/requires.txt +0 -2
- indoxrouter-0.1.0/setup.py +0 -26
- {indoxrouter-0.1.0/indoxrouter.egg-info → indoxrouter-0.1.2/indoxRouter.egg-info}/dependency_links.txt +0 -0
- {indoxrouter-0.1.0/indoxrouter.egg-info → indoxrouter-0.1.2/indoxRouter.egg-info}/top_level.txt +0 -0
- {indoxrouter-0.1.0 → indoxrouter-0.1.2}/setup.cfg +0 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 indoxRouter Team
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,259 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: indoxrouter
|
3
|
+
Version: 0.1.2
|
4
|
+
Summary: A unified interface for various LLM providers
|
5
|
+
Home-page: https://github.com/indoxrouter/indoxrouter
|
6
|
+
Author: indoxRouter Team
|
7
|
+
Author-email: ashkan.eskandari.dev@gmail.com
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
9
|
+
Classifier: Intended Audience :: Developers
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
16
|
+
Requires-Python: >=3.8
|
17
|
+
Description-Content-Type: text/markdown
|
18
|
+
License-File: LICENSE
|
19
|
+
Requires-Dist: requests>=2.25.0
|
20
|
+
Requires-Dist: openai>=1.0.0
|
21
|
+
Requires-Dist: PyJWT>=2.0.0
|
22
|
+
Requires-Dist: tiktoken>=0.4.0
|
23
|
+
Provides-Extra: dev
|
24
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
25
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
26
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
27
|
+
Requires-Dist: isort>=5.0.0; extra == "dev"
|
28
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
29
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
30
|
+
Provides-Extra: postgres
|
31
|
+
Requires-Dist: psycopg2-binary>=2.9.5; extra == "postgres"
|
32
|
+
Provides-Extra: all
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "all"
|
34
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "all"
|
35
|
+
Requires-Dist: black>=23.0.0; extra == "all"
|
36
|
+
Requires-Dist: isort>=5.0.0; extra == "all"
|
37
|
+
Requires-Dist: flake8>=6.0.0; extra == "all"
|
38
|
+
Requires-Dist: mypy>=1.0.0; extra == "all"
|
39
|
+
Requires-Dist: psycopg2-binary>=2.9.5; extra == "all"
|
40
|
+
Dynamic: author
|
41
|
+
Dynamic: author-email
|
42
|
+
Dynamic: classifier
|
43
|
+
Dynamic: description
|
44
|
+
Dynamic: description-content-type
|
45
|
+
Dynamic: home-page
|
46
|
+
Dynamic: provides-extra
|
47
|
+
Dynamic: requires-dist
|
48
|
+
Dynamic: requires-python
|
49
|
+
Dynamic: summary
|
50
|
+
|
51
|
+
# indoxRouter
|
52
|
+
|
53
|
+
<p align="center">
|
54
|
+
<img src="https://raw.githubusercontent.com/indoxrouter/indoxrouter/main/docs/assets/logo.png" alt="indoxRouter Logo" width="200"/>
|
55
|
+
</p>
|
56
|
+
|
57
|
+
<p align="center">
|
58
|
+
<strong>A unified interface for various LLM providers</strong>
|
59
|
+
</p>
|
60
|
+
|
61
|
+
<p align="center">
|
62
|
+
<a href="https://pypi.org/project/indoxRouter/"><img src="https://img.shields.io/pypi/v/indoxRouter.svg" alt="PyPI version"></a>
|
63
|
+
<a href="https://github.com/indoxrouter/indoxrouter/blob/main/LICENSE"><img src="https://img.shields.io/github/license/indoxrouter/indoxrouter" alt="License"></a>
|
64
|
+
<a href="https://github.com/indoxrouter/indoxrouter/stargazers"><img src="https://img.shields.io/github/stars/indoxrouter/indoxrouter" alt="GitHub stars"></a>
|
65
|
+
</p>
|
66
|
+
|
67
|
+
## Overview
|
68
|
+
|
69
|
+
indoxRouter is a powerful Python library that provides a unified interface to interact with various Large Language Model (LLM) providers. With a single API key, you can access models from OpenAI, Anthropic, Mistral, Google, and more, without having to manage multiple provider-specific API keys and implementations.
|
70
|
+
|
71
|
+
### Key Features
|
72
|
+
|
73
|
+
- **Single API for Multiple Providers**: Access models from OpenAI, Anthropic, Mistral, Google, and more with a single API key
|
74
|
+
- **Standardized Response Format**: Consistent response format across all providers
|
75
|
+
- **Streaming Support**: Stream responses for real-time applications
|
76
|
+
- **Cost Tracking**: Track token usage and costs across providers
|
77
|
+
- **Rate Limiting**: Built-in rate limiting to prevent exceeding provider quotas
|
78
|
+
- **Error Handling**: Comprehensive error handling with detailed error messages
|
79
|
+
- **Authentication**: Secure authentication with JWT tokens
|
80
|
+
- **Type Hints**: Full type hints for better IDE support
|
81
|
+
|
82
|
+
## Installation
|
83
|
+
|
84
|
+
```bash
|
85
|
+
pip install indoxRouter
|
86
|
+
```
|
87
|
+
|
88
|
+
For development:
|
89
|
+
|
90
|
+
```bash
|
91
|
+
pip install indoxRouter[dev]
|
92
|
+
```
|
93
|
+
|
94
|
+
## Quick Start
|
95
|
+
|
96
|
+
```python
|
97
|
+
from indoxRouter import Client
|
98
|
+
from indoxRouter.models import ChatMessage
|
99
|
+
|
100
|
+
# Initialize the client with your API key
|
101
|
+
client = Client(api_key="your-api-key")
|
102
|
+
|
103
|
+
# Chat completion with OpenAI
|
104
|
+
response = client.chat(
|
105
|
+
messages=[
|
106
|
+
{"role": "user", "content": "What are three fun activities to do in New York?"}
|
107
|
+
],
|
108
|
+
model="openai/gpt-4o-mini",
|
109
|
+
temperature=0.7,
|
110
|
+
max_tokens=500,
|
111
|
+
)
|
112
|
+
|
113
|
+
print(response.data)
|
114
|
+
```
|
115
|
+
|
116
|
+
## Available Providers
|
117
|
+
|
118
|
+
indoxRouter supports the following providers:
|
119
|
+
|
120
|
+
- OpenAI
|
121
|
+
- Anthropic (Claude)
|
122
|
+
- Mistral
|
123
|
+
- Google
|
124
|
+
- Cohere
|
125
|
+
|
126
|
+
## Core Features
|
127
|
+
|
128
|
+
### Chat Completion
|
129
|
+
|
130
|
+
```python
|
131
|
+
response = client.chat(
|
132
|
+
messages=[
|
133
|
+
{"role": "user", "content": "What are three fun activities to do in New York?"}
|
134
|
+
],
|
135
|
+
model="openai/gpt-4o-mini",
|
136
|
+
temperature=0.7,
|
137
|
+
max_tokens=500,
|
138
|
+
)
|
139
|
+
```
|
140
|
+
|
141
|
+
### Text Completion
|
142
|
+
|
143
|
+
```python
|
144
|
+
response = client.completion(
|
145
|
+
prompt="Write a short story about a robot learning to paint.",
|
146
|
+
model="anthropic/claude-3-haiku",
|
147
|
+
temperature=0.7,
|
148
|
+
max_tokens=500,
|
149
|
+
)
|
150
|
+
```
|
151
|
+
|
152
|
+
### Embeddings
|
153
|
+
|
154
|
+
```python
|
155
|
+
response = client.embeddings(
|
156
|
+
text="This is a sample text to embed.",
|
157
|
+
model="openai/text-embedding-3-small",
|
158
|
+
)
|
159
|
+
```
|
160
|
+
|
161
|
+
### Image Generation
|
162
|
+
|
163
|
+
```python
|
164
|
+
response = client.image(
|
165
|
+
prompt="A futuristic city with flying cars and neon lights",
|
166
|
+
model="openai/dall-e-3",
|
167
|
+
size="1024x1024",
|
168
|
+
)
|
169
|
+
```
|
170
|
+
|
171
|
+
### Streaming
|
172
|
+
|
173
|
+
```python
|
174
|
+
generator = client.chat(
|
175
|
+
messages=[
|
176
|
+
{"role": "user", "content": "Write a short story about a robot learning to paint."}
|
177
|
+
],
|
178
|
+
model="openai/gpt-4o-mini",
|
179
|
+
temperature=0.7,
|
180
|
+
max_tokens=500,
|
181
|
+
stream=True,
|
182
|
+
return_generator=True,
|
183
|
+
)
|
184
|
+
|
185
|
+
for chunk in generator:
|
186
|
+
if isinstance(chunk, dict) and chunk.get("is_usage_info"):
|
187
|
+
# This is the final usage info
|
188
|
+
usage_info = chunk
|
189
|
+
else:
|
190
|
+
# This is a content chunk
|
191
|
+
print(chunk, end="", flush=True)
|
192
|
+
```
|
193
|
+
|
194
|
+
## Provider and Model Information
|
195
|
+
|
196
|
+
```python
|
197
|
+
# List all available providers
|
198
|
+
providers = client.providers()
|
199
|
+
|
200
|
+
# List all available models
|
201
|
+
models = client.models()
|
202
|
+
|
203
|
+
# List models for a specific provider
|
204
|
+
openai_models = client.models(provider="openai")
|
205
|
+
|
206
|
+
# Get information about a specific model
|
207
|
+
model_info = client.model_info(provider="openai", model="gpt-4o-mini")
|
208
|
+
```
|
209
|
+
|
210
|
+
## Configuration
|
211
|
+
|
212
|
+
indoxRouter can be configured using environment variables or a configuration file:
|
213
|
+
|
214
|
+
```python
|
215
|
+
# Set API key via environment variable
|
216
|
+
import os
|
217
|
+
os.environ["INDOX_ROUTER_API_KEY"] = "your-api-key"
|
218
|
+
|
219
|
+
# Or provide it directly to the client
|
220
|
+
client = Client(api_key="your-api-key")
|
221
|
+
```
|
222
|
+
|
223
|
+
## Error Handling
|
224
|
+
|
225
|
+
indoxRouter provides comprehensive error handling:
|
226
|
+
|
227
|
+
```python
|
228
|
+
from indoxRouter import Client
|
229
|
+
from indoxRouter.exceptions import AuthenticationError, RateLimitError, ProviderError
|
230
|
+
|
231
|
+
try:
|
232
|
+
client = Client(api_key="invalid-api-key")
|
233
|
+
except AuthenticationError as e:
|
234
|
+
print(f"Authentication error: {e}")
|
235
|
+
|
236
|
+
try:
|
237
|
+
response = client.chat(
|
238
|
+
messages=[{"role": "user", "content": "Hello"}],
|
239
|
+
model="nonexistent-model",
|
240
|
+
)
|
241
|
+
except ProviderError as e:
|
242
|
+
print(f"Provider error: {e}")
|
243
|
+
```
|
244
|
+
|
245
|
+
## Documentation
|
246
|
+
|
247
|
+
For detailed documentation, visit [https://docs.indoxrouter.com](https://docs.indoxrouter.com).
|
248
|
+
|
249
|
+
## Examples
|
250
|
+
|
251
|
+
Check out the [examples](https://github.com/indoxrouter/indoxrouter/tree/main/examples) directory for more examples.
|
252
|
+
|
253
|
+
## Contributing
|
254
|
+
|
255
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
256
|
+
|
257
|
+
## License
|
258
|
+
|
259
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# indoxRouter
|
2
|
+
|
3
|
+
<p align="center">
|
4
|
+
<img src="https://raw.githubusercontent.com/indoxrouter/indoxrouter/main/docs/assets/logo.png" alt="indoxRouter Logo" width="200"/>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<p align="center">
|
8
|
+
<strong>A unified interface for various LLM providers</strong>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p align="center">
|
12
|
+
<a href="https://pypi.org/project/indoxRouter/"><img src="https://img.shields.io/pypi/v/indoxRouter.svg" alt="PyPI version"></a>
|
13
|
+
<a href="https://github.com/indoxrouter/indoxrouter/blob/main/LICENSE"><img src="https://img.shields.io/github/license/indoxrouter/indoxrouter" alt="License"></a>
|
14
|
+
<a href="https://github.com/indoxrouter/indoxrouter/stargazers"><img src="https://img.shields.io/github/stars/indoxrouter/indoxrouter" alt="GitHub stars"></a>
|
15
|
+
</p>
|
16
|
+
|
17
|
+
## Overview
|
18
|
+
|
19
|
+
indoxRouter is a powerful Python library that provides a unified interface to interact with various Large Language Model (LLM) providers. With a single API key, you can access models from OpenAI, Anthropic, Mistral, Google, and more, without having to manage multiple provider-specific API keys and implementations.
|
20
|
+
|
21
|
+
### Key Features
|
22
|
+
|
23
|
+
- **Single API for Multiple Providers**: Access models from OpenAI, Anthropic, Mistral, Google, and more with a single API key
|
24
|
+
- **Standardized Response Format**: Consistent response format across all providers
|
25
|
+
- **Streaming Support**: Stream responses for real-time applications
|
26
|
+
- **Cost Tracking**: Track token usage and costs across providers
|
27
|
+
- **Rate Limiting**: Built-in rate limiting to prevent exceeding provider quotas
|
28
|
+
- **Error Handling**: Comprehensive error handling with detailed error messages
|
29
|
+
- **Authentication**: Secure authentication with JWT tokens
|
30
|
+
- **Type Hints**: Full type hints for better IDE support
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
```bash
|
35
|
+
pip install indoxRouter
|
36
|
+
```
|
37
|
+
|
38
|
+
For development:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
pip install indoxRouter[dev]
|
42
|
+
```
|
43
|
+
|
44
|
+
## Quick Start
|
45
|
+
|
46
|
+
```python
|
47
|
+
from indoxRouter import Client
|
48
|
+
from indoxRouter.models import ChatMessage
|
49
|
+
|
50
|
+
# Initialize the client with your API key
|
51
|
+
client = Client(api_key="your-api-key")
|
52
|
+
|
53
|
+
# Chat completion with OpenAI
|
54
|
+
response = client.chat(
|
55
|
+
messages=[
|
56
|
+
{"role": "user", "content": "What are three fun activities to do in New York?"}
|
57
|
+
],
|
58
|
+
model="openai/gpt-4o-mini",
|
59
|
+
temperature=0.7,
|
60
|
+
max_tokens=500,
|
61
|
+
)
|
62
|
+
|
63
|
+
print(response.data)
|
64
|
+
```
|
65
|
+
|
66
|
+
## Available Providers
|
67
|
+
|
68
|
+
indoxRouter supports the following providers:
|
69
|
+
|
70
|
+
- OpenAI
|
71
|
+
- Anthropic (Claude)
|
72
|
+
- Mistral
|
73
|
+
- Google
|
74
|
+
- Cohere
|
75
|
+
|
76
|
+
## Core Features
|
77
|
+
|
78
|
+
### Chat Completion
|
79
|
+
|
80
|
+
```python
|
81
|
+
response = client.chat(
|
82
|
+
messages=[
|
83
|
+
{"role": "user", "content": "What are three fun activities to do in New York?"}
|
84
|
+
],
|
85
|
+
model="openai/gpt-4o-mini",
|
86
|
+
temperature=0.7,
|
87
|
+
max_tokens=500,
|
88
|
+
)
|
89
|
+
```
|
90
|
+
|
91
|
+
### Text Completion
|
92
|
+
|
93
|
+
```python
|
94
|
+
response = client.completion(
|
95
|
+
prompt="Write a short story about a robot learning to paint.",
|
96
|
+
model="anthropic/claude-3-haiku",
|
97
|
+
temperature=0.7,
|
98
|
+
max_tokens=500,
|
99
|
+
)
|
100
|
+
```
|
101
|
+
|
102
|
+
### Embeddings
|
103
|
+
|
104
|
+
```python
|
105
|
+
response = client.embeddings(
|
106
|
+
text="This is a sample text to embed.",
|
107
|
+
model="openai/text-embedding-3-small",
|
108
|
+
)
|
109
|
+
```
|
110
|
+
|
111
|
+
### Image Generation
|
112
|
+
|
113
|
+
```python
|
114
|
+
response = client.image(
|
115
|
+
prompt="A futuristic city with flying cars and neon lights",
|
116
|
+
model="openai/dall-e-3",
|
117
|
+
size="1024x1024",
|
118
|
+
)
|
119
|
+
```
|
120
|
+
|
121
|
+
### Streaming
|
122
|
+
|
123
|
+
```python
|
124
|
+
generator = client.chat(
|
125
|
+
messages=[
|
126
|
+
{"role": "user", "content": "Write a short story about a robot learning to paint."}
|
127
|
+
],
|
128
|
+
model="openai/gpt-4o-mini",
|
129
|
+
temperature=0.7,
|
130
|
+
max_tokens=500,
|
131
|
+
stream=True,
|
132
|
+
return_generator=True,
|
133
|
+
)
|
134
|
+
|
135
|
+
for chunk in generator:
|
136
|
+
if isinstance(chunk, dict) and chunk.get("is_usage_info"):
|
137
|
+
# This is the final usage info
|
138
|
+
usage_info = chunk
|
139
|
+
else:
|
140
|
+
# This is a content chunk
|
141
|
+
print(chunk, end="", flush=True)
|
142
|
+
```
|
143
|
+
|
144
|
+
## Provider and Model Information
|
145
|
+
|
146
|
+
```python
|
147
|
+
# List all available providers
|
148
|
+
providers = client.providers()
|
149
|
+
|
150
|
+
# List all available models
|
151
|
+
models = client.models()
|
152
|
+
|
153
|
+
# List models for a specific provider
|
154
|
+
openai_models = client.models(provider="openai")
|
155
|
+
|
156
|
+
# Get information about a specific model
|
157
|
+
model_info = client.model_info(provider="openai", model="gpt-4o-mini")
|
158
|
+
```
|
159
|
+
|
160
|
+
## Configuration
|
161
|
+
|
162
|
+
indoxRouter can be configured using environment variables or a configuration file:
|
163
|
+
|
164
|
+
```python
|
165
|
+
# Set API key via environment variable
|
166
|
+
import os
|
167
|
+
os.environ["INDOX_ROUTER_API_KEY"] = "your-api-key"
|
168
|
+
|
169
|
+
# Or provide it directly to the client
|
170
|
+
client = Client(api_key="your-api-key")
|
171
|
+
```
|
172
|
+
|
173
|
+
## Error Handling
|
174
|
+
|
175
|
+
indoxRouter provides comprehensive error handling:
|
176
|
+
|
177
|
+
```python
|
178
|
+
from indoxRouter import Client
|
179
|
+
from indoxRouter.exceptions import AuthenticationError, RateLimitError, ProviderError
|
180
|
+
|
181
|
+
try:
|
182
|
+
client = Client(api_key="invalid-api-key")
|
183
|
+
except AuthenticationError as e:
|
184
|
+
print(f"Authentication error: {e}")
|
185
|
+
|
186
|
+
try:
|
187
|
+
response = client.chat(
|
188
|
+
messages=[{"role": "user", "content": "Hello"}],
|
189
|
+
model="nonexistent-model",
|
190
|
+
)
|
191
|
+
except ProviderError as e:
|
192
|
+
print(f"Provider error: {e}")
|
193
|
+
```
|
194
|
+
|
195
|
+
## Documentation
|
196
|
+
|
197
|
+
For detailed documentation, visit [https://docs.indoxrouter.com](https://docs.indoxrouter.com).
|
198
|
+
|
199
|
+
## Examples
|
200
|
+
|
201
|
+
Check out the [examples](https://github.com/indoxrouter/indoxrouter/tree/main/examples) directory for more examples.
|
202
|
+
|
203
|
+
## Contributing
|
204
|
+
|
205
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
206
|
+
|
207
|
+
## License
|
208
|
+
|
209
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
@@ -0,0 +1,83 @@
|
|
1
|
+
"""
|
2
|
+
indoxRouter - A unified interface for various LLM providers.
|
3
|
+
|
4
|
+
This package provides a simple and consistent way to interact with different
|
5
|
+
LLM providers like OpenAI, Claude, Mistral, and more.
|
6
|
+
"""
|
7
|
+
|
8
|
+
__version__ = "0.1.0"
|
9
|
+
|
10
|
+
from .client import Client, IndoxRouter
|
11
|
+
from .config import Config, get_config
|
12
|
+
from .models import (
|
13
|
+
ChatMessage,
|
14
|
+
ChatResponse,
|
15
|
+
CompletionResponse,
|
16
|
+
EmbeddingResponse,
|
17
|
+
ImageResponse,
|
18
|
+
ModelInfo,
|
19
|
+
Usage,
|
20
|
+
)
|
21
|
+
from .exceptions import (
|
22
|
+
IndoxRouterError,
|
23
|
+
AuthenticationError,
|
24
|
+
ProviderError,
|
25
|
+
ProviderNotFoundError,
|
26
|
+
ModelNotFoundError,
|
27
|
+
InvalidParametersError,
|
28
|
+
RequestError,
|
29
|
+
)
|
30
|
+
from .constants import (
|
31
|
+
DEFAULT_TEMPERATURE,
|
32
|
+
DEFAULT_MAX_TOKENS,
|
33
|
+
DEFAULT_TOP_P,
|
34
|
+
DEFAULT_FREQUENCY_PENALTY,
|
35
|
+
DEFAULT_PRESENCE_PENALTY,
|
36
|
+
DEFAULT_IMAGE_SIZE,
|
37
|
+
DEFAULT_IMAGE_COUNT,
|
38
|
+
)
|
39
|
+
from .utils import (
|
40
|
+
count_tokens,
|
41
|
+
calculate_cost,
|
42
|
+
format_timestamp,
|
43
|
+
)
|
44
|
+
|
45
|
+
__all__ = [
|
46
|
+
# Main client
|
47
|
+
"Client",
|
48
|
+
"IndoxRouter",
|
49
|
+
# Configuration
|
50
|
+
"Config",
|
51
|
+
"get_config",
|
52
|
+
# Database
|
53
|
+
"Database",
|
54
|
+
"get_database",
|
55
|
+
# Models
|
56
|
+
"ChatMessage",
|
57
|
+
"ChatResponse",
|
58
|
+
"CompletionResponse",
|
59
|
+
"EmbeddingResponse",
|
60
|
+
"ImageResponse",
|
61
|
+
"ModelInfo",
|
62
|
+
"Usage",
|
63
|
+
# Exceptions
|
64
|
+
"IndoxRouterError",
|
65
|
+
"AuthenticationError",
|
66
|
+
"ProviderError",
|
67
|
+
"ProviderNotFoundError",
|
68
|
+
"ModelNotFoundError",
|
69
|
+
"InvalidParametersError",
|
70
|
+
"RequestError",
|
71
|
+
# Constants
|
72
|
+
"DEFAULT_TEMPERATURE",
|
73
|
+
"DEFAULT_MAX_TOKENS",
|
74
|
+
"DEFAULT_TOP_P",
|
75
|
+
"DEFAULT_FREQUENCY_PENALTY",
|
76
|
+
"DEFAULT_PRESENCE_PENALTY",
|
77
|
+
"DEFAULT_IMAGE_SIZE",
|
78
|
+
"DEFAULT_IMAGE_COUNT",
|
79
|
+
# Utilities
|
80
|
+
"count_tokens",
|
81
|
+
"calculate_cost",
|
82
|
+
"format_timestamp",
|
83
|
+
]
|