azure-llm-toolkit 0.1.1__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.
Files changed (35) hide show
  1. azure_llm_toolkit-0.1.1/.env.example +29 -0
  2. azure_llm_toolkit-0.1.1/.gitignore +15 -0
  3. azure_llm_toolkit-0.1.1/.python-version +1 -0
  4. azure_llm_toolkit-0.1.1/CONTRIBUTING.md +352 -0
  5. azure_llm_toolkit-0.1.1/LICENSE +21 -0
  6. azure_llm_toolkit-0.1.1/MIGRATION_GUIDE.md +405 -0
  7. azure_llm_toolkit-0.1.1/PKG-INFO +627 -0
  8. azure_llm_toolkit-0.1.1/PROJECT_SUMMARY.md +333 -0
  9. azure_llm_toolkit-0.1.1/README.md +586 -0
  10. azure_llm_toolkit-0.1.1/examples/basic_usage.py +277 -0
  11. azure_llm_toolkit-0.1.1/examples/batch_embedding_example.py +274 -0
  12. azure_llm_toolkit-0.1.1/examples/caching_example.py +330 -0
  13. azure_llm_toolkit-0.1.1/pyproject.toml +90 -0
  14. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/__init__.py +194 -0
  15. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/analytics.py +565 -0
  16. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/batch_embedder.py +406 -0
  17. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/cache.py +377 -0
  18. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/circuit_breaker.py +404 -0
  19. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/client.py +603 -0
  20. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/config.py +293 -0
  21. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/cost_tracker.py +396 -0
  22. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/dashboard.py +325 -0
  23. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/metrics.py +439 -0
  24. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/py.typed +0 -0
  25. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/rate_limiter.py +255 -0
  26. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/streaming.py +462 -0
  27. azure_llm_toolkit-0.1.1/src/azure_llm_toolkit/types.py +131 -0
  28. azure_llm_toolkit-0.1.1/tests/__init__.py +1 -0
  29. azure_llm_toolkit-0.1.1/tests/conftest.py +65 -0
  30. azure_llm_toolkit-0.1.1/tests/test_batch_embedder.py +163 -0
  31. azure_llm_toolkit-0.1.1/tests/test_cache.py +297 -0
  32. azure_llm_toolkit-0.1.1/tests/test_client.py +133 -0
  33. azure_llm_toolkit-0.1.1/tests/test_live_rate_limits.py +296 -0
  34. azure_llm_toolkit-0.1.1/tests/test_rate_limiter_integration.py +276 -0
  35. azure_llm_toolkit-0.1.1/uv.lock +1353 -0
@@ -0,0 +1,29 @@
1
+ # Azure OpenAI Configuration
2
+ # Copy this file to .env and fill in your values
3
+
4
+ # Required: Azure OpenAI API Key
5
+ AZURE_OPENAI_API_KEY=your-api-key-here
6
+ # Or use OPENAI_API_KEY as an alternative
7
+ # OPENAI_API_KEY=your-api-key-here
8
+
9
+ # Required: Azure OpenAI Endpoint
10
+ AZURE_ENDPOINT=https://your-resource.openai.azure.com
11
+ # Or use AZURE_OPENAI_ENDPOINT as an alternative
12
+ # AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
13
+
14
+ # Optional: API Version (default: 2024-12-01-preview)
15
+ AZURE_API_VERSION=2024-12-01-preview
16
+
17
+ # Optional: Deployment Names
18
+ AZURE_CHAT_DEPLOYMENT=gpt-4o
19
+ AZURE_EMBEDDING_DEPLOYMENT=text-embedding-3-large
20
+
21
+ # Optional: Request Configuration
22
+ AZURE_TIMEOUT_SECONDS=60
23
+ AZURE_MAX_RETRIES=5
24
+
25
+ # Optional: Tokenizer Model (default: gpt-4o)
26
+ TOKENIZER_MODEL=gpt-4o
27
+
28
+ # Optional: Force Embedding Dimension (for testing/offline mode)
29
+ # FORCE_EMBED_DIM=3072
@@ -0,0 +1,15 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Environment and local caches
13
+ .env
14
+ .llm_cache/
15
+ live_costs.jsonl
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,352 @@
1
+ # Contributing to Azure LLM Toolkit
2
+
3
+ Thank you for your interest in contributing to Azure LLM Toolkit! This document provides guidelines and instructions for contributing.
4
+
5
+ ## Code of Conduct
6
+
7
+ Please be respectful and constructive in all interactions. We aim to foster an inclusive and welcoming community.
8
+
9
+ ## Getting Started
10
+
11
+ ### Prerequisites
12
+
13
+ - Python 3.10 or higher
14
+ - Git
15
+ - An Azure OpenAI account (for testing)
16
+
17
+ ### Development Setup
18
+
19
+ 1. **Fork and clone the repository**
20
+
21
+ ```bash
22
+ git clone https://github.com/YOUR_USERNAME/azure-llm-toolkit.git
23
+ cd azure-llm-toolkit
24
+ ```
25
+
26
+ 2. **Create a virtual environment**
27
+
28
+ ```bash
29
+ python -m venv .venv
30
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
31
+ ```
32
+
33
+ 3. **Install dependencies**
34
+
35
+ ```bash
36
+ pip install -e ".[dev]"
37
+ ```
38
+
39
+ 4. **Set up environment variables**
40
+
41
+ ```bash
42
+ cp .env.example .env
43
+ # Edit .env with your Azure OpenAI credentials
44
+ ```
45
+
46
+ 5. **Run tests to verify setup**
47
+
48
+ ```bash
49
+ pytest
50
+ ```
51
+
52
+ ## Development Workflow
53
+
54
+ ### Branch Naming
55
+
56
+ - `feature/` - New features (e.g., `feature/add-streaming-support`)
57
+ - `fix/` - Bug fixes (e.g., `fix/rate-limiter-edge-case`)
58
+ - `docs/` - Documentation changes (e.g., `docs/improve-readme`)
59
+ - `refactor/` - Code refactoring (e.g., `refactor/simplify-config`)
60
+
61
+ ### Making Changes
62
+
63
+ 1. **Create a feature branch**
64
+
65
+ ```bash
66
+ git checkout -b feature/your-feature-name
67
+ ```
68
+
69
+ 2. **Make your changes**
70
+
71
+ - Write clear, concise code
72
+ - Follow the existing code style
73
+ - Add docstrings to new functions/classes
74
+ - Update type hints
75
+
76
+ 3. **Add tests**
77
+
78
+ - Write tests for new functionality
79
+ - Ensure existing tests still pass
80
+ - Aim for high test coverage
81
+
82
+ 4. **Update documentation**
83
+
84
+ - Update README.md if adding user-facing features
85
+ - Add docstrings with examples
86
+ - Update CHANGELOG.md
87
+
88
+ 5. **Run quality checks**
89
+
90
+ ```bash
91
+ # Format code
92
+ ruff format .
93
+
94
+ # Lint code
95
+ ruff check .
96
+
97
+ # Type checking
98
+ basedpyright src/
99
+ mypy src/
100
+
101
+ # Run tests
102
+ pytest
103
+
104
+ # Run tests with coverage
105
+ pytest --cov=azure_llm_toolkit --cov-report=html
106
+ ```
107
+
108
+ ## Code Style
109
+
110
+ ### Python Style Guide
111
+
112
+ We follow PEP 8 with some modifications:
113
+
114
+ - **Line length**: 120 characters (configured in pyproject.toml)
115
+ - **Imports**: Organized using `ruff` (isort rules)
116
+ - **Type hints**: Required for all public functions and methods
117
+ - **Docstrings**: Google-style docstrings for all public APIs
118
+
119
+ ### Type Hints
120
+
121
+ Use modern Python type hints:
122
+
123
+ ```python
124
+ # Good
125
+ def process_items(items: list[str]) -> dict[str, int]:
126
+ ...
127
+
128
+ # Avoid
129
+ from typing import List, Dict
130
+ def process_items(items: List[str]) -> Dict[str, int]:
131
+ ...
132
+ ```
133
+
134
+ ### Docstring Format
135
+
136
+ Use Google-style docstrings:
137
+
138
+ ```python
139
+ def example_function(param1: str, param2: int) -> bool:
140
+ """
141
+ Brief description of function.
142
+
143
+ Longer description if needed. Can span multiple lines.
144
+
145
+ Args:
146
+ param1: Description of param1
147
+ param2: Description of param2
148
+
149
+ Returns:
150
+ Description of return value
151
+
152
+ Raises:
153
+ ValueError: When input is invalid
154
+ RuntimeError: When operation fails
155
+
156
+ Example:
157
+ >>> result = example_function("test", 42)
158
+ >>> print(result)
159
+ True
160
+ """
161
+ ...
162
+ ```
163
+
164
+ ## Testing
165
+
166
+ ### Running Tests
167
+
168
+ ```bash
169
+ # Run all tests
170
+ pytest
171
+
172
+ # Run specific test file
173
+ pytest tests/test_client.py
174
+
175
+ # Run with coverage
176
+ pytest --cov=azure_llm_toolkit --cov-report=html
177
+
178
+ # Run tests matching a pattern
179
+ pytest -k "test_embeddings"
180
+ ```
181
+
182
+ ### Writing Tests
183
+
184
+ - Use `pytest` conventions
185
+ - Use `pytest-asyncio` for async tests
186
+ - Mock external API calls when possible
187
+ - Test both success and failure cases
188
+
189
+ Example test:
190
+
191
+ ```python
192
+ import pytest
193
+ from azure_llm_toolkit import AzureConfig, AzureLLMClient
194
+
195
+ @pytest.mark.asyncio
196
+ async def test_embed_texts():
197
+ """Test basic text embedding functionality."""
198
+ config = AzureConfig()
199
+ client = AzureLLMClient(config=config)
200
+
201
+ texts = ["test text"]
202
+ result = await client.embed_texts(texts)
203
+
204
+ assert len(result.embeddings) == 1
205
+ assert len(result.embeddings[0]) > 0
206
+ assert result.usage.total_tokens > 0
207
+ ```
208
+
209
+ ## Pull Request Process
210
+
211
+ 1. **Ensure all checks pass**
212
+
213
+ - All tests pass
214
+ - Code is formatted
215
+ - No linting errors
216
+ - Type checking passes
217
+
218
+ 2. **Update documentation**
219
+
220
+ - Update README.md if needed
221
+ - Add entry to CHANGELOG.md
222
+ - Update docstrings
223
+
224
+ 3. **Create pull request**
225
+
226
+ - Use a clear, descriptive title
227
+ - Reference related issues (e.g., "Fixes #123")
228
+ - Provide detailed description of changes
229
+ - Include examples if adding new features
230
+
231
+ 4. **PR Template**
232
+
233
+ ```markdown
234
+ ## Description
235
+ Brief description of changes
236
+
237
+ ## Type of Change
238
+ - [ ] Bug fix
239
+ - [ ] New feature
240
+ - [ ] Breaking change
241
+ - [ ] Documentation update
242
+
243
+ ## Checklist
244
+ - [ ] Tests added/updated
245
+ - [ ] Documentation updated
246
+ - [ ] CHANGELOG.md updated
247
+ - [ ] All tests pass
248
+ - [ ] Code formatted with ruff
249
+ - [ ] Type checking passes
250
+
251
+ ## Related Issues
252
+ Fixes #(issue number)
253
+ ```
254
+
255
+ ## Commit Messages
256
+
257
+ Use clear, descriptive commit messages:
258
+
259
+ ```bash
260
+ # Good
261
+ git commit -m "Add support for streaming responses
262
+
263
+ - Implement streaming for chat completions
264
+ - Add tests for streaming functionality
265
+ - Update documentation with streaming examples"
266
+
267
+ # Less good
268
+ git commit -m "fix bug"
269
+ ```
270
+
271
+ ### Commit Message Format
272
+
273
+ ```
274
+ <type>: <subject>
275
+
276
+ <body>
277
+
278
+ <footer>
279
+ ```
280
+
281
+ **Types:**
282
+ - `feat`: New feature
283
+ - `fix`: Bug fix
284
+ - `docs`: Documentation changes
285
+ - `style`: Code style changes (formatting, etc.)
286
+ - `refactor`: Code refactoring
287
+ - `test`: Adding or updating tests
288
+ - `chore`: Maintenance tasks
289
+
290
+ ## Reporting Issues
291
+
292
+ ### Bug Reports
293
+
294
+ Include:
295
+ - Clear description of the bug
296
+ - Steps to reproduce
297
+ - Expected behavior
298
+ - Actual behavior
299
+ - Environment details (Python version, OS, etc.)
300
+ - Code samples if applicable
301
+
302
+ ### Feature Requests
303
+
304
+ Include:
305
+ - Clear description of the feature
306
+ - Use cases and motivation
307
+ - Example API or usage pattern
308
+ - Any alternatives considered
309
+
310
+ ## Documentation
311
+
312
+ ### Updating Documentation
313
+
314
+ - Keep README.md up to date
315
+ - Add examples for new features
316
+ - Update API reference if needed
317
+ - Check for broken links
318
+
319
+ ### Documentation Style
320
+
321
+ - Use clear, concise language
322
+ - Provide code examples
323
+ - Include expected output
324
+ - Link to related concepts
325
+
326
+ ## Release Process
327
+
328
+ (For maintainers)
329
+
330
+ 1. Update version in `pyproject.toml`
331
+ 2. Update CHANGELOG.md
332
+ 3. Create git tag: `git tag -a v0.2.0 -m "Release v0.2.0"`
333
+ 4. Push tag: `git push origin v0.2.0`
334
+ 5. Build and publish to PyPI:
335
+
336
+ ```bash
337
+ # Build package
338
+ python -m build
339
+
340
+ # Upload to PyPI
341
+ python -m twine upload dist/*
342
+ ```
343
+
344
+ ## Questions?
345
+
346
+ If you have questions about contributing:
347
+
348
+ - Open an issue with the `question` label
349
+ - Check existing issues and discussions
350
+ - Review the README.md and documentation
351
+
352
+ Thank you for contributing to Azure LLM Toolkit! 🎉
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Torstein Sørnes
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.