callosum-sdk 0.2.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.
- callosum_sdk-0.2.1/.gitignore +9 -0
- callosum_sdk-0.2.1/LICENSE +180 -0
- callosum_sdk-0.2.1/PKG-INFO +93 -0
- callosum_sdk-0.2.1/README.md +63 -0
- callosum_sdk-0.2.1/pyproject.toml +66 -0
- callosum_sdk-0.2.1/src/callosum_sdk/__init__.py +41 -0
- callosum_sdk-0.2.1/src/callosum_sdk/batching/__init__.py +34 -0
- callosum_sdk-0.2.1/src/callosum_sdk/batching/_queue.py +56 -0
- callosum_sdk-0.2.1/src/callosum_sdk/batching/_validation.py +84 -0
- callosum_sdk-0.2.1/src/callosum_sdk/batching/client.py +567 -0
- callosum_sdk-0.2.1/src/callosum_sdk/batching/errors.py +83 -0
- callosum_sdk-0.2.1/src/callosum_sdk/py.typed +1 -0
- callosum_sdk-0.2.1/src/callosum_sdk/spot/__init__.py +5 -0
- callosum_sdk-0.2.1/src/callosum_sdk/spot/client.py +147 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submit" means any form of electronic, verbal, or
|
|
51
|
+
written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of tracking
|
|
55
|
+
modifications made to the Work.
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
58
|
+
whom a Contribution has been received by the Licensor and included
|
|
59
|
+
within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
65
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
66
|
+
Work and such Derivative Works in Source or Object form.
|
|
67
|
+
|
|
68
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
(except as stated in this section) patent license to make, have made,
|
|
72
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
73
|
+
where such license applies only to those patent claims licensable
|
|
74
|
+
by such Contributor that are necessarily infringed by their
|
|
75
|
+
Contribution(s) alone or by the combination of their Contributions
|
|
76
|
+
with the Work to which such Contributions were submitted. If You
|
|
77
|
+
institute patent litigation against any entity (including a cross-claim
|
|
78
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
79
|
+
Contribution embodied within the Work constitutes direct or
|
|
80
|
+
contributory patent infringement, then any patent licenses granted
|
|
81
|
+
to You under this License for that Work shall terminate as of the
|
|
82
|
+
date such litigation is filed.
|
|
83
|
+
|
|
84
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
85
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
86
|
+
modifications, and in Source or Object form, provided that You
|
|
87
|
+
meet the following conditions:
|
|
88
|
+
|
|
89
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
90
|
+
Works a copy of this License; and
|
|
91
|
+
|
|
92
|
+
(b) You must cause any modified files to carry prominent notices
|
|
93
|
+
stating that You changed the files; and
|
|
94
|
+
|
|
95
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
96
|
+
that You distribute, all copyright, patent, trademark, and
|
|
97
|
+
attribution notices from the Source form of the Work,
|
|
98
|
+
excluding those notices that do not pertain to any part of
|
|
99
|
+
the Derivative Works; and
|
|
100
|
+
|
|
101
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
102
|
+
distribution, You must include a readable copy of the
|
|
103
|
+
attribution notices contained within such NOTICE file, in
|
|
104
|
+
at least one of the following places: within a NOTICE text
|
|
105
|
+
file distributed as part of the Derivative Works; within
|
|
106
|
+
the Source form or documentation, if provided along with the
|
|
107
|
+
Derivative Works; or, within a display generated by the
|
|
108
|
+
Derivative Works, if and wherever such third-party notices
|
|
109
|
+
normally appear. The contents of the NOTICE file are for
|
|
110
|
+
informational purposes only and do not modify the License.
|
|
111
|
+
You may add Your own attribution notices within Derivative
|
|
112
|
+
Works that You distribute, alongside or in addition to the
|
|
113
|
+
NOTICE text from the Work, provided that such additional
|
|
114
|
+
attribution notices cannot be construed as modifying the
|
|
115
|
+
License.
|
|
116
|
+
|
|
117
|
+
You may add Your own license statement for Your modifications and
|
|
118
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
119
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
120
|
+
Derivative Works, and to permit persons to whom the Derivative Works
|
|
121
|
+
is furnished to do so, subject to the following conditions.
|
|
122
|
+
|
|
123
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
124
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
125
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
126
|
+
this License, without any additional terms or conditions.
|
|
127
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
128
|
+
the terms of any separate license agreement you may have executed
|
|
129
|
+
with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
133
|
+
except as required for reasonable and customary use in describing the
|
|
134
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
137
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
138
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
140
|
+
implied, including, without limitation, any warranties or conditions
|
|
141
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
142
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
143
|
+
appropriateness of using or reproducing the Work and assume any
|
|
144
|
+
risks associated with Your exercise of permissions under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
147
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
148
|
+
unless required by applicable law (such as deliberate and grossly
|
|
149
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
150
|
+
liable to You for damages, including any direct, indirect, special,
|
|
151
|
+
incidental, or exemplary damages of any character arising as a
|
|
152
|
+
result of this License or out of the use or inability to use the
|
|
153
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
154
|
+
work stoppage, computer failure or malfunction, or all other
|
|
155
|
+
commercial damages or losses), even if such Contributor has been
|
|
156
|
+
advised of the possibility of such damages.
|
|
157
|
+
|
|
158
|
+
9. Accepting Warranty or Liability. While redistributing the Work or
|
|
159
|
+
Derivative Works thereof, You may choose to offer, and charge a fee
|
|
160
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
161
|
+
obligations and/or rights consistent with this License. However, in
|
|
162
|
+
accepting such obligations, You may offer only obligations consistent
|
|
163
|
+
with this License, and only in a charge that is reasonable, in
|
|
164
|
+
light of the services offered.
|
|
165
|
+
|
|
166
|
+
END OF TERMS AND CONDITIONS
|
|
167
|
+
|
|
168
|
+
Copyright 2026 Hamzah Chariwala
|
|
169
|
+
|
|
170
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
171
|
+
you may not use this file except in compliance with the License.
|
|
172
|
+
You may obtain a copy of the License at
|
|
173
|
+
|
|
174
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
175
|
+
|
|
176
|
+
Unless required by applicable law or agreed to in writing, software
|
|
177
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
178
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
179
|
+
See the License for the specific language governing permissions and
|
|
180
|
+
limitations under the License.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: callosum-sdk
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: AsyncOpenAI-compatible client for Callosum spot inference
|
|
5
|
+
Project-URL: Homepage, https://github.com/callosumtechnologies/callosum-sdk
|
|
6
|
+
Project-URL: Repository, https://github.com/callosumtechnologies/callosum-sdk
|
|
7
|
+
Project-URL: Issues, https://github.com/callosumtechnologies/callosum-sdk/issues
|
|
8
|
+
Author: Callosum Technologies
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: batch,callosum,inference,openai
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: httpx>=0.27
|
|
22
|
+
Requires-Dist: openai>=2.53.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pyright>=1.1.403; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-cov>=6; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.12; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# callosum-sdk
|
|
32
|
+
|
|
33
|
+
callosum-sdk provides an AsyncOpenAI-compatible client for latency-insensitive
|
|
34
|
+
models running on spot capacity. A familiar chat-completions call becomes a
|
|
35
|
+
background submit/poll operation without holding an HTTP connection across a
|
|
36
|
+
GPU cold start.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
~~~bash
|
|
41
|
+
pip install callosum-sdk
|
|
42
|
+
~~~
|
|
43
|
+
|
|
44
|
+
## Quickstart
|
|
45
|
+
|
|
46
|
+
~~~python
|
|
47
|
+
import asyncio
|
|
48
|
+
import os
|
|
49
|
+
|
|
50
|
+
from callosum_sdk import AsyncOpenAI
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
async def main() -> None:
|
|
54
|
+
async with AsyncOpenAI(
|
|
55
|
+
api_key=os.environ["CALLOSUM_API_KEY"],
|
|
56
|
+
base_url=os.environ.get("CALLOSUM_BASE_URL", "https://api.callosum.ai/v1"),
|
|
57
|
+
) as client:
|
|
58
|
+
response = await client.chat.completions.create(
|
|
59
|
+
model="qwen3.5-4b",
|
|
60
|
+
messages=[{"role": "user", "content": "Explain quantum computing"}],
|
|
61
|
+
)
|
|
62
|
+
print(response.choices[0].message.content)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
asyncio.run(main())
|
|
66
|
+
~~~
|
|
67
|
+
|
|
68
|
+
Run `uv run demo-readme` from a source checkout to execute that exact Quickstart
|
|
69
|
+
block. Set `CALLOSUM_BASE_URL` to target a staging gateway or port-forward;
|
|
70
|
+
otherwise it defaults to the public API.
|
|
71
|
+
|
|
72
|
+
The SDK sends the public slug as `spot/qwen3.5-4b`, which selects the
|
|
73
|
+
gateway's spot proxy. The gateway maps that slug through its deployed model
|
|
74
|
+
catalogue and forwards to the spot orchestrator's background API. The returned
|
|
75
|
+
response still reports `qwen3.5-4b`, keeping the routing namespace
|
|
76
|
+
transparent to application code.
|
|
77
|
+
|
|
78
|
+
## Behaviour and limits
|
|
79
|
+
|
|
80
|
+
- `chat.completions.create()` is non-streaming: it submits immediately, polls
|
|
81
|
+
every five seconds, and returns a typed OpenAI `ChatCompletion` at completion.
|
|
82
|
+
- The default one-hour client wait can be changed with
|
|
83
|
+
`request_timeout_seconds`; the request continues in the orchestrator if a
|
|
84
|
+
local caller is cancelled.
|
|
85
|
+
- `model_prefix="spot/"` is idempotent. Passing an already namespaced model does
|
|
86
|
+
not produce `spot/spot/...`.
|
|
87
|
+
- The API key identifies the tenant. A response id submitted by one tenant
|
|
88
|
+
cannot be polled by another.
|
|
89
|
+
- Raw Files and Batch API batching remains available through the explicit
|
|
90
|
+
`BatchOpenAI` class for non-spot workload batches.
|
|
91
|
+
|
|
92
|
+
See [the spot client guide](docs/spot/README.md) for the routing contract and
|
|
93
|
+
[the batching guide](docs/batching/README.md) for `BatchOpenAI`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# callosum-sdk
|
|
2
|
+
|
|
3
|
+
callosum-sdk provides an AsyncOpenAI-compatible client for latency-insensitive
|
|
4
|
+
models running on spot capacity. A familiar chat-completions call becomes a
|
|
5
|
+
background submit/poll operation without holding an HTTP connection across a
|
|
6
|
+
GPU cold start.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
~~~bash
|
|
11
|
+
pip install callosum-sdk
|
|
12
|
+
~~~
|
|
13
|
+
|
|
14
|
+
## Quickstart
|
|
15
|
+
|
|
16
|
+
~~~python
|
|
17
|
+
import asyncio
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
from callosum_sdk import AsyncOpenAI
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
async def main() -> None:
|
|
24
|
+
async with AsyncOpenAI(
|
|
25
|
+
api_key=os.environ["CALLOSUM_API_KEY"],
|
|
26
|
+
base_url=os.environ.get("CALLOSUM_BASE_URL", "https://api.callosum.ai/v1"),
|
|
27
|
+
) as client:
|
|
28
|
+
response = await client.chat.completions.create(
|
|
29
|
+
model="qwen3.5-4b",
|
|
30
|
+
messages=[{"role": "user", "content": "Explain quantum computing"}],
|
|
31
|
+
)
|
|
32
|
+
print(response.choices[0].message.content)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
asyncio.run(main())
|
|
36
|
+
~~~
|
|
37
|
+
|
|
38
|
+
Run `uv run demo-readme` from a source checkout to execute that exact Quickstart
|
|
39
|
+
block. Set `CALLOSUM_BASE_URL` to target a staging gateway or port-forward;
|
|
40
|
+
otherwise it defaults to the public API.
|
|
41
|
+
|
|
42
|
+
The SDK sends the public slug as `spot/qwen3.5-4b`, which selects the
|
|
43
|
+
gateway's spot proxy. The gateway maps that slug through its deployed model
|
|
44
|
+
catalogue and forwards to the spot orchestrator's background API. The returned
|
|
45
|
+
response still reports `qwen3.5-4b`, keeping the routing namespace
|
|
46
|
+
transparent to application code.
|
|
47
|
+
|
|
48
|
+
## Behaviour and limits
|
|
49
|
+
|
|
50
|
+
- `chat.completions.create()` is non-streaming: it submits immediately, polls
|
|
51
|
+
every five seconds, and returns a typed OpenAI `ChatCompletion` at completion.
|
|
52
|
+
- The default one-hour client wait can be changed with
|
|
53
|
+
`request_timeout_seconds`; the request continues in the orchestrator if a
|
|
54
|
+
local caller is cancelled.
|
|
55
|
+
- `model_prefix="spot/"` is idempotent. Passing an already namespaced model does
|
|
56
|
+
not produce `spot/spot/...`.
|
|
57
|
+
- The API key identifies the tenant. A response id submitted by one tenant
|
|
58
|
+
cannot be polled by another.
|
|
59
|
+
- Raw Files and Batch API batching remains available through the explicit
|
|
60
|
+
`BatchOpenAI` class for non-spot workload batches.
|
|
61
|
+
|
|
62
|
+
See [the spot client guide](docs/spot/README.md) for the routing contract and
|
|
63
|
+
[the batching guide](docs/batching/README.md) for `BatchOpenAI`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "callosum-sdk"
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "AsyncOpenAI-compatible client for Callosum spot inference"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
authors = [{ name = "Callosum Technologies" }]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
keywords = ["callosum", "openai", "batch", "inference"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: Apache Software License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
dependencies = ["httpx>=0.27", "openai>=2.53.0"]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
dev = [
|
|
28
|
+
"pyright>=1.1.403",
|
|
29
|
+
"pytest>=8.3",
|
|
30
|
+
"pytest-asyncio>=0.24",
|
|
31
|
+
"pytest-cov>=6",
|
|
32
|
+
"ruff>=0.12",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/callosumtechnologies/callosum-sdk"
|
|
37
|
+
Repository = "https://github.com/callosumtechnologies/callosum-sdk"
|
|
38
|
+
Issues = "https://github.com/callosumtechnologies/callosum-sdk/issues"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["src/callosum_sdk"]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.sdist]
|
|
44
|
+
include = ["/LICENSE", "/README.md", "/pyproject.toml", "/src/callosum_sdk"]
|
|
45
|
+
|
|
46
|
+
[tool.uv.workspace]
|
|
47
|
+
members = ["scripts"]
|
|
48
|
+
|
|
49
|
+
[tool.ruff]
|
|
50
|
+
line-length = 100
|
|
51
|
+
target-version = "py312"
|
|
52
|
+
|
|
53
|
+
[tool.ruff.lint]
|
|
54
|
+
select = ["E", "F", "W", "I", "UP"]
|
|
55
|
+
|
|
56
|
+
[tool.pyright]
|
|
57
|
+
pythonVersion = "3.12"
|
|
58
|
+
typeCheckingMode = "basic"
|
|
59
|
+
|
|
60
|
+
[tool.pytest.ini_options]
|
|
61
|
+
addopts = "--import-mode=importlib"
|
|
62
|
+
asyncio_mode = "auto"
|
|
63
|
+
testpaths = ["tests"]
|
|
64
|
+
|
|
65
|
+
[tool.coverage.run]
|
|
66
|
+
source = ["callosum_sdk"]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Public interface for the Callosum Python SDK."""
|
|
2
|
+
|
|
3
|
+
from callosum_sdk.batching import (
|
|
4
|
+
BatchExpiredError,
|
|
5
|
+
BatchFailedError,
|
|
6
|
+
BatchNotEnabledError,
|
|
7
|
+
BatchOpenAI,
|
|
8
|
+
BatchRequestError,
|
|
9
|
+
CallosumSDKError,
|
|
10
|
+
ClientClosedError,
|
|
11
|
+
MissingBatchResultError,
|
|
12
|
+
NotSupportedError,
|
|
13
|
+
RequestValidationError,
|
|
14
|
+
SpotRequestError,
|
|
15
|
+
SpotTimeoutError,
|
|
16
|
+
StreamingNotSupportedError,
|
|
17
|
+
)
|
|
18
|
+
from callosum_sdk.spot import SpotOpenAI
|
|
19
|
+
|
|
20
|
+
AsyncOpenAI = SpotOpenAI
|
|
21
|
+
|
|
22
|
+
__version__ = "0.2.1"
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"AsyncOpenAI",
|
|
26
|
+
"BatchExpiredError",
|
|
27
|
+
"BatchFailedError",
|
|
28
|
+
"BatchNotEnabledError",
|
|
29
|
+
"BatchOpenAI",
|
|
30
|
+
"BatchRequestError",
|
|
31
|
+
"CallosumSDKError",
|
|
32
|
+
"ClientClosedError",
|
|
33
|
+
"MissingBatchResultError",
|
|
34
|
+
"NotSupportedError",
|
|
35
|
+
"RequestValidationError",
|
|
36
|
+
"StreamingNotSupportedError",
|
|
37
|
+
"SpotOpenAI",
|
|
38
|
+
"SpotRequestError",
|
|
39
|
+
"SpotTimeoutError",
|
|
40
|
+
"__version__",
|
|
41
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Transparent batching client and its public errors."""
|
|
2
|
+
|
|
3
|
+
from callosum_sdk.batching.client import AsyncOpenAI, BatchOpenAI
|
|
4
|
+
from callosum_sdk.batching.errors import (
|
|
5
|
+
BatchExpiredError,
|
|
6
|
+
BatchFailedError,
|
|
7
|
+
BatchNotEnabledError,
|
|
8
|
+
BatchRequestError,
|
|
9
|
+
CallosumSDKError,
|
|
10
|
+
ClientClosedError,
|
|
11
|
+
MissingBatchResultError,
|
|
12
|
+
NotSupportedError,
|
|
13
|
+
RequestValidationError,
|
|
14
|
+
SpotRequestError,
|
|
15
|
+
SpotTimeoutError,
|
|
16
|
+
StreamingNotSupportedError,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"AsyncOpenAI",
|
|
21
|
+
"BatchExpiredError",
|
|
22
|
+
"BatchFailedError",
|
|
23
|
+
"BatchNotEnabledError",
|
|
24
|
+
"BatchOpenAI",
|
|
25
|
+
"BatchRequestError",
|
|
26
|
+
"CallosumSDKError",
|
|
27
|
+
"ClientClosedError",
|
|
28
|
+
"MissingBatchResultError",
|
|
29
|
+
"NotSupportedError",
|
|
30
|
+
"RequestValidationError",
|
|
31
|
+
"StreamingNotSupportedError",
|
|
32
|
+
"SpotRequestError",
|
|
33
|
+
"SpotTimeoutError",
|
|
34
|
+
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Pending-request queue isolated by endpoint and model."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections import deque
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
QueueKey = tuple[str, str]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(slots=True)
|
|
14
|
+
class PendingRequest[ResultT]:
|
|
15
|
+
custom_id: str
|
|
16
|
+
endpoint: str
|
|
17
|
+
model: str
|
|
18
|
+
body: dict[str, Any]
|
|
19
|
+
encoded_line: bytes
|
|
20
|
+
future: asyncio.Future[ResultT]
|
|
21
|
+
result_type: type[ResultT]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class PendingQueue:
|
|
25
|
+
"""FIFO queues keyed by the gateway's batch-homogeneity fields."""
|
|
26
|
+
|
|
27
|
+
def __init__(self) -> None:
|
|
28
|
+
self._items: dict[QueueKey, deque[PendingRequest[Any]]] = {}
|
|
29
|
+
|
|
30
|
+
def append(self, key: QueueKey, request: PendingRequest[Any]) -> int:
|
|
31
|
+
queue = self._items.setdefault(key, deque())
|
|
32
|
+
queue.append(request)
|
|
33
|
+
return len(queue)
|
|
34
|
+
|
|
35
|
+
def take(self, key: QueueKey, count: int) -> list[PendingRequest[Any]]:
|
|
36
|
+
queue = self._items.get(key)
|
|
37
|
+
if not queue:
|
|
38
|
+
return []
|
|
39
|
+
taken = [queue.popleft() for _ in range(min(count, len(queue)))]
|
|
40
|
+
if not queue:
|
|
41
|
+
self._items.pop(key, None)
|
|
42
|
+
return taken
|
|
43
|
+
|
|
44
|
+
def pop_all(self, key: QueueKey) -> list[PendingRequest[Any]]:
|
|
45
|
+
return list(self._items.pop(key, ()))
|
|
46
|
+
|
|
47
|
+
def keys(self) -> tuple[QueueKey, ...]:
|
|
48
|
+
return tuple(self._items)
|
|
49
|
+
|
|
50
|
+
def count(self, key: QueueKey) -> int:
|
|
51
|
+
return len(self._items.get(key, ()))
|
|
52
|
+
|
|
53
|
+
def clear(self) -> list[PendingRequest[Any]]:
|
|
54
|
+
requests = [request for queue in self._items.values() for request in queue]
|
|
55
|
+
self._items.clear()
|
|
56
|
+
return requests
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Client-side validation for Callosum batch input files."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Iterable, Mapping, Sequence
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from callosum_sdk.batching.errors import RequestValidationError
|
|
10
|
+
|
|
11
|
+
CHAT_COMPLETIONS_ENDPOINT = "/v1/chat/completions"
|
|
12
|
+
GATEWAY_MAX_LINES = 50_000
|
|
13
|
+
GATEWAY_MAX_BYTES = 200 * 1024 * 1024
|
|
14
|
+
DEFAULT_MAX_BATCH_LINES = 49_000
|
|
15
|
+
DEFAULT_MAX_BATCH_BYTES = 190 * 1024 * 1024
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def validate_client_options(
|
|
19
|
+
*,
|
|
20
|
+
batch_size: int,
|
|
21
|
+
batch_window_seconds: float,
|
|
22
|
+
poll_interval_seconds: float,
|
|
23
|
+
completion_window: str,
|
|
24
|
+
) -> None:
|
|
25
|
+
if batch_size <= 0:
|
|
26
|
+
raise RequestValidationError("batch_size must be greater than zero")
|
|
27
|
+
if batch_window_seconds < 0:
|
|
28
|
+
raise RequestValidationError("batch_window_seconds must not be negative")
|
|
29
|
+
if poll_interval_seconds <= 0:
|
|
30
|
+
raise RequestValidationError("poll_interval_seconds must be greater than zero")
|
|
31
|
+
if completion_window != "24h":
|
|
32
|
+
raise RequestValidationError("Callosum's Batch API requires completion_window='24h'")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def validate_chat_request(model: object, messages: object, stream: object) -> str:
|
|
36
|
+
if not isinstance(model, str) or not model:
|
|
37
|
+
raise RequestValidationError("model must be a non-empty string")
|
|
38
|
+
if isinstance(messages, (str, bytes)) or not isinstance(messages, Iterable):
|
|
39
|
+
raise RequestValidationError("messages must be an iterable of chat messages")
|
|
40
|
+
if stream is True:
|
|
41
|
+
from callosum_sdk.batching.errors import StreamingNotSupportedError
|
|
42
|
+
|
|
43
|
+
raise StreamingNotSupportedError(
|
|
44
|
+
"Callosum batch chat completions do not support stream=True"
|
|
45
|
+
)
|
|
46
|
+
return model
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def validate_batch_lines(lines: Sequence[Mapping[str, Any]], *, endpoint: str, model: str) -> None:
|
|
50
|
+
"""Validate all gateway-wide invariants before an input file is uploaded."""
|
|
51
|
+
if not lines:
|
|
52
|
+
raise RequestValidationError("A batch input file cannot be empty")
|
|
53
|
+
if len(lines) > GATEWAY_MAX_LINES:
|
|
54
|
+
raise RequestValidationError(f"A batch cannot exceed {GATEWAY_MAX_LINES} requests")
|
|
55
|
+
|
|
56
|
+
custom_ids: set[str] = set()
|
|
57
|
+
for index, line in enumerate(lines, start=1):
|
|
58
|
+
custom_id = line.get("custom_id")
|
|
59
|
+
if not isinstance(custom_id, str) or not custom_id:
|
|
60
|
+
raise RequestValidationError(f"Line {index} has no non-empty custom_id")
|
|
61
|
+
if custom_id in custom_ids:
|
|
62
|
+
raise RequestValidationError(f"Line {index} duplicates custom_id {custom_id!r}")
|
|
63
|
+
custom_ids.add(custom_id)
|
|
64
|
+
if line.get("method") != "POST":
|
|
65
|
+
raise RequestValidationError(f"Line {index} must use method='POST'")
|
|
66
|
+
if line.get("url") != endpoint:
|
|
67
|
+
raise RequestValidationError(f"Line {index} URL must match {endpoint!r}")
|
|
68
|
+
body = line.get("body")
|
|
69
|
+
if not isinstance(body, Mapping):
|
|
70
|
+
raise RequestValidationError(f"Line {index} body must be an object")
|
|
71
|
+
if body.get("model") != model:
|
|
72
|
+
raise RequestValidationError(f"Line {index} model must match {model!r}")
|
|
73
|
+
if body.get("stream") is True:
|
|
74
|
+
raise RequestValidationError(f"Line {index} must not enable streaming")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def encoded_jsonl(lines: Sequence[Mapping[str, Any]]) -> bytes:
|
|
78
|
+
content = b"".join(
|
|
79
|
+
json.dumps(line, separators=(",", ":"), ensure_ascii=False).encode("utf-8") + b"\n"
|
|
80
|
+
for line in lines
|
|
81
|
+
)
|
|
82
|
+
if len(content) > GATEWAY_MAX_BYTES:
|
|
83
|
+
raise RequestValidationError(f"A batch input file cannot exceed {GATEWAY_MAX_BYTES} bytes")
|
|
84
|
+
return content
|