inferenceswitch 0.1.0__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 (33) hide show
  1. inferenceswitch-0.1.0/.gitattributes +2 -0
  2. inferenceswitch-0.1.0/.github/workflows/ci.yml +51 -0
  3. inferenceswitch-0.1.0/.github/workflows/release.yml +104 -0
  4. inferenceswitch-0.1.0/.gitignore +26 -0
  5. inferenceswitch-0.1.0/CHANGELOG.md +34 -0
  6. inferenceswitch-0.1.0/CONTRIBUTING.md +40 -0
  7. inferenceswitch-0.1.0/LICENSE +21 -0
  8. inferenceswitch-0.1.0/PKG-INFO +476 -0
  9. inferenceswitch-0.1.0/README.md +438 -0
  10. inferenceswitch-0.1.0/RELEASING.md +73 -0
  11. inferenceswitch-0.1.0/SECURITY.md +34 -0
  12. inferenceswitch-0.1.0/examples/prompt_caching.py +107 -0
  13. inferenceswitch-0.1.0/inferenceswitch/__init__.py +104 -0
  14. inferenceswitch-0.1.0/inferenceswitch/adapters/__init__.py +34 -0
  15. inferenceswitch-0.1.0/inferenceswitch/adapters/anthropic.py +433 -0
  16. inferenceswitch-0.1.0/inferenceswitch/adapters/base.py +152 -0
  17. inferenceswitch-0.1.0/inferenceswitch/adapters/gemini.py +480 -0
  18. inferenceswitch-0.1.0/inferenceswitch/adapters/openai_compat.py +283 -0
  19. inferenceswitch-0.1.0/inferenceswitch/capabilities.py +98 -0
  20. inferenceswitch-0.1.0/inferenceswitch/client.py +527 -0
  21. inferenceswitch-0.1.0/inferenceswitch/errors.py +57 -0
  22. inferenceswitch-0.1.0/inferenceswitch/messages.py +212 -0
  23. inferenceswitch-0.1.0/inferenceswitch/registry.py +296 -0
  24. inferenceswitch-0.1.0/inferenceswitch/schema.py +162 -0
  25. inferenceswitch-0.1.0/pyproject.toml +50 -0
  26. inferenceswitch-0.1.0/tests/test_capabilities.py +134 -0
  27. inferenceswitch-0.1.0/tests/test_chat.py +251 -0
  28. inferenceswitch-0.1.0/tests/test_gemini_max_tokens.py +248 -0
  29. inferenceswitch-0.1.0/tests/test_max_tokens.py +156 -0
  30. inferenceswitch-0.1.0/tests/test_prompt_caching.py +329 -0
  31. inferenceswitch-0.1.0/tests/test_reasoning.py +74 -0
  32. inferenceswitch-0.1.0/tests/test_resolution.py +64 -0
  33. inferenceswitch-0.1.0/tests/test_schema.py +172 -0
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ name: pytest (py${{ matrix.python-version }})
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ python-version: ["3.10", "3.11", "3.12"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ cache: pip
24
+
25
+ # The `dev` extra pulls every provider SDK. The suite makes no network
26
+ # calls -- adapters are exercised against fakes -- so this is only needed
27
+ # for the SDK types the adapters import.
28
+ - name: Install
29
+ run: |
30
+ python -m pip install --upgrade pip
31
+ pip install -e ".[dev]"
32
+
33
+ - name: Run tests
34
+ run: pytest -q
35
+
36
+ build:
37
+ name: package builds and is well-formed
38
+ runs-on: ubuntu-latest
39
+ steps:
40
+ - uses: actions/checkout@v4
41
+ - uses: actions/setup-python@v5
42
+ with:
43
+ python-version: "3.12"
44
+ - name: Build and check metadata
45
+ run: |
46
+ python -m pip install --upgrade pip build twine
47
+ python -m build
48
+ # --strict to match the release workflow. Without it CI can pass on a
49
+ # warning that then fails the release, which is the wrong way round:
50
+ # the cheap gate should be at least as strict as the expensive one.
51
+ twine check --strict dist/*
@@ -0,0 +1,104 @@
1
+ name: Release
2
+
3
+ # Two ways in:
4
+ # * publishing a GitHub Release -> PyPI. The release is the trigger, so the
5
+ # tag, the release notes and the upload are one action rather than three
6
+ # that can drift apart.
7
+ # * manual dispatch -> TestPyPI, for rehearsing a release without burning a
8
+ # version number. PyPI refuses to replace an existing file, so a botched
9
+ # real upload cannot be corrected in place -- only yanked and re-numbered.
10
+ on:
11
+ release:
12
+ types: [published]
13
+ workflow_dispatch:
14
+ inputs:
15
+ target:
16
+ description: "Where to upload"
17
+ required: true
18
+ default: testpypi
19
+ type: choice
20
+ options: [testpypi]
21
+
22
+ jobs:
23
+ build:
24
+ name: Build sdist and wheel
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+
29
+ - uses: actions/setup-python@v5
30
+ with:
31
+ python-version: "3.12"
32
+
33
+ # The version lives in pyproject.toml and the tag is typed by hand, so
34
+ # they can disagree. Catch that here rather than after an unfixable
35
+ # upload: publishing 0.1.0 from a v0.2.0 tag is not correctable, since
36
+ # PyPI will not let that filename be reused even after a yank.
37
+ - name: Tag and pyproject version agree
38
+ if: github.event_name == 'release'
39
+ run: |
40
+ python - <<'PY'
41
+ import os, sys, tomllib
42
+ tag = os.environ["TAG"].removeprefix("v")
43
+ declared = tomllib.load(open("pyproject.toml", "rb"))["project"]["version"]
44
+ if tag != declared:
45
+ sys.exit(f"tag {tag!r} != pyproject version {declared!r}")
46
+ print(f"version {declared} matches tag")
47
+ PY
48
+ env:
49
+ TAG: ${{ github.event.release.tag_name }}
50
+
51
+ - name: Build
52
+ run: |
53
+ python -m pip install --upgrade pip build twine
54
+ python -m build
55
+ twine check --strict dist/*
56
+
57
+ - uses: actions/upload-artifact@v4
58
+ with:
59
+ name: dist
60
+ path: dist/
61
+
62
+ pypi:
63
+ name: Publish to PyPI
64
+ needs: build
65
+ if: github.event_name == 'release'
66
+ runs-on: ubuntu-latest
67
+ # Named environment so the upload can be gated on a required reviewer in
68
+ # repo settings, and so PyPI's trusted publisher can be scoped to it.
69
+ environment:
70
+ name: pypi
71
+ url: https://pypi.org/p/inferenceswitch
72
+ permissions:
73
+ # The whole authentication story. Trusted Publishing mints a short-lived
74
+ # OIDC token for this specific workflow in this specific repo, so there
75
+ # is no long-lived API token in repo secrets to leak or rotate.
76
+ id-token: write
77
+ steps:
78
+ - uses: actions/download-artifact@v4
79
+ with:
80
+ name: dist
81
+ path: dist/
82
+ - uses: pypa/gh-action-pypi-publish@release/v1
83
+
84
+ testpypi:
85
+ name: Publish to TestPyPI
86
+ needs: build
87
+ if: github.event_name == 'workflow_dispatch'
88
+ runs-on: ubuntu-latest
89
+ environment:
90
+ name: testpypi
91
+ url: https://test.pypi.org/p/inferenceswitch
92
+ permissions:
93
+ id-token: write
94
+ steps:
95
+ - uses: actions/download-artifact@v4
96
+ with:
97
+ name: dist
98
+ path: dist/
99
+ - uses: pypa/gh-action-pypi-publish@release/v1
100
+ with:
101
+ repository-url: https://test.pypi.org/legacy/
102
+ # A rehearsal should not fail because the same version was rehearsed
103
+ # before. Never set this on the real PyPI job.
104
+ skip-existing: true
@@ -0,0 +1,26 @@
1
+ # Caches
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .mypy_cache/
7
+ .coverage
8
+ htmlcov/
9
+
10
+ # Packaging / build output
11
+ build/
12
+ dist/
13
+ *.egg-info/
14
+ .eggs/
15
+
16
+ # Environments & local secrets
17
+ .venv/
18
+ venv/
19
+ env/
20
+ .env
21
+ *$py.class
22
+
23
+ # Editor / OS
24
+ .idea/
25
+ .vscode/
26
+ .DS_Store
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. This project adheres to
4
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] — first public release
9
+
10
+ Initial release. Developed privately as `llmswitch` and renamed for
11
+ publication: that name was crowded on both PyPI and GitHub, and `llm` was too
12
+ narrow for a library that already dispatches to local small-model servers
13
+ (`ollama`, `lmstudio`) alongside the hosted providers.
14
+
15
+ - Static provider registry with prefix, `provider/model`, and explicit routing.
16
+ Unroutable or ambiguous model strings raise `ProviderResolutionError` — there
17
+ is no silent default provider.
18
+ - Uniform structured-JSON and plain-text generation across Anthropic, Gemini,
19
+ OpenAI, and OpenAI-compatible providers (Mistral, DeepSeek, Groq, Ollama,
20
+ LM Studio).
21
+ - Schema-dialect translation for Gemini's `response_schema`, which rejects
22
+ `additionalProperties`: dict-typed nodes are rewritten to key/value arrays and
23
+ folded back on the way out. Driven by the caller's own schema, including
24
+ `$defs` / `$ref` and `anyOf`-wrapped optional dicts.
25
+ - Per-model output caps, with a process-wide table as the control surface.
26
+ - Portable prompt-caching surface across providers.
27
+ - Capability introspection (`models_for`, effort control, assertions).
28
+ - Zero required dependencies; provider SDKs are optional extras, lazily imported.
29
+
30
+ The entry points are `Client` and `Response`, unprefixed like every other
31
+ export (`Message`, `Tool`, `Usage`, `Capability`). They were `LLMClient` and
32
+ `LLMResponse` during private development; the prefix was dropped for the same
33
+ reason `llm` left the package name, and because the package already qualifies
34
+ them.
@@ -0,0 +1,40 @@
1
+ # Contributing
2
+
3
+ Thanks for taking a look.
4
+
5
+ ## Getting set up
6
+
7
+ ```bash
8
+ pip install -e ".[dev]"
9
+ pytest -q
10
+ ```
11
+
12
+ The suite makes **no network calls** — adapters are exercised against fakes — so
13
+ it runs in about a second and needs no API keys.
14
+
15
+ ## What this library is, and is not
16
+
17
+ Scope discipline is the main design constraint, so it is worth stating before
18
+ you open a PR:
19
+
20
+ - It is an **import-only** library. No proxy server, no plugin system, no
21
+ dynamic provider loading.
22
+ - It does **not** own key storage or encryption. Applications with per-user keys
23
+ pass a `key_provider`.
24
+ - It contains **no logging**. Please keep it that way — it is what makes "keys
25
+ are never logged" a structural guarantee rather than a promise.
26
+ - Base URLs come from the static registry and are not caller-injectable.
27
+
28
+ ## Adding a provider
29
+
30
+ See *Adding a provider* in the README. Most OpenAI-compatible providers need a
31
+ registry entry and nothing else; a provider with its own structured-output
32
+ mechanism needs an adapter.
33
+
34
+ ## Pull requests
35
+
36
+ - Add tests. New provider behaviour should be covered against a fake rather than
37
+ a live endpoint.
38
+ - Keep commit subjects in the imperative, prefixed with an area:
39
+ `gemini: request an output ceiling`.
40
+ - Note any user-visible change in `CHANGELOG.md` under `[Unreleased]`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 IDEMS International
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.