byom 0.2.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.
- byom-0.2.0/.dockerignore +6 -0
- byom-0.2.0/.github/workflows/ci.yml +18 -0
- byom-0.2.0/.github/workflows/python-publish.yml +26 -0
- byom-0.2.0/.gitignore +18 -0
- byom-0.2.0/.python-version +1 -0
- byom-0.2.0/LICENSE +21 -0
- byom-0.2.0/Makefile +25 -0
- byom-0.2.0/PKG-INFO +170 -0
- byom-0.2.0/README.md +128 -0
- byom-0.2.0/byom/__init__.py +6 -0
- byom-0.2.0/byom/cli.py +106 -0
- byom-0.2.0/byom/deploy/__init__.py +83 -0
- byom-0.2.0/byom/deploy/docker.py +107 -0
- byom-0.2.0/byom/deploy/modal/__init__.py +86 -0
- byom-0.2.0/byom/deploy/modal/app.py +95 -0
- byom-0.2.0/byom/profiles/__init__.py +61 -0
- byom-0.2.0/byom/profiles/qwen3-coder-30b.yaml +13 -0
- byom-0.2.0/byom/proxy.py +127 -0
- byom-0.2.0/docker/proxy.Dockerfile +10 -0
- byom-0.2.0/docs/usage.md +131 -0
- byom-0.2.0/examples/anthropic_sdk.py +60 -0
- byom-0.2.0/examples/claude_code_qwen.sh +29 -0
- byom-0.2.0/examples/d1_snake.py +164 -0
- byom-0.2.0/examples/openai_sdk.py +100 -0
- byom-0.2.0/pyproject.toml +71 -0
- byom-0.2.0/skills/byom/SKILL.md +92 -0
- byom-0.2.0/tests/test_deploy.py +75 -0
- byom-0.2.0/tests/test_live.py +155 -0
- byom-0.2.0/tests/test_proxy.py +132 -0
- byom-0.2.0/uv.lock +2005 -0
byom-0.2.0/.dockerignore
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
check:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: astral-sh/setup-uv@v6
|
|
17
|
+
- run: uv sync --all-extras
|
|
18
|
+
- run: make check
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
environment: pypi
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write # PyPI trusted publishing; no API token needed
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: astral-sh/setup-uv@v6
|
|
16
|
+
- name: Tag matches pyproject version
|
|
17
|
+
run: |
|
|
18
|
+
version=$(uv version --short)
|
|
19
|
+
if [ "${GITHUB_REF_NAME#v}" != "$version" ]; then
|
|
20
|
+
echo "release tag $GITHUB_REF_NAME doesn't match version $version in pyproject.toml"
|
|
21
|
+
exit 1
|
|
22
|
+
fi
|
|
23
|
+
- run: uv sync --all-extras
|
|
24
|
+
- run: make check
|
|
25
|
+
- run: uv build
|
|
26
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
byom-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
byom-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shyam Sudhakaran
|
|
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.
|
byom-0.2.0/Makefile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.PHONY: install test live lint check bump image
|
|
2
|
+
.DEFAULT_GOAL := check
|
|
3
|
+
NAME ?= qwen3-coder-30b
|
|
4
|
+
PART ?= patch
|
|
5
|
+
|
|
6
|
+
install:
|
|
7
|
+
uv sync --all-extras
|
|
8
|
+
|
|
9
|
+
test:
|
|
10
|
+
uv run pytest
|
|
11
|
+
|
|
12
|
+
live: ## end-to-end tests against a deployment: make live NAME=<deployment>
|
|
13
|
+
BYOM_LIVE=$(NAME) uv run pytest tests/test_live.py -v
|
|
14
|
+
|
|
15
|
+
lint:
|
|
16
|
+
uv run ruff check byom tests examples
|
|
17
|
+
uv run mypy
|
|
18
|
+
|
|
19
|
+
check: lint test
|
|
20
|
+
|
|
21
|
+
bump: ## make bump PART=patch|minor|major, then release tag v<new version>
|
|
22
|
+
uv version --bump $(PART)
|
|
23
|
+
|
|
24
|
+
image: ## build the proxy image from this checkout
|
|
25
|
+
docker build -f docker/proxy.Dockerfile -t byom:local .
|
byom-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: byom
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Bring your own model to Claude Code: deploy SGLang on Modal or Docker, with a proxy in front.
|
|
5
|
+
Project-URL: Repository, https://github.com/shyamsn97/byom
|
|
6
|
+
Author-email: Shyam Sudhakaran <shyamsnair@protonmail.com>
|
|
7
|
+
License: The MIT License (MIT)
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Shyam Sudhakaran
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Keywords: claude-code,inference,llm,modal,sglang
|
|
30
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Classifier: Topic :: Software Development
|
|
33
|
+
Requires-Python: >=3.11
|
|
34
|
+
Requires-Dist: httpx>=0.28
|
|
35
|
+
Requires-Dist: pyyaml>=6
|
|
36
|
+
Requires-Dist: starlette>=0.41
|
|
37
|
+
Requires-Dist: typer>=0.15
|
|
38
|
+
Requires-Dist: uvicorn>=0.32
|
|
39
|
+
Provides-Extra: modal
|
|
40
|
+
Requires-Dist: modal>=1.6; extra == 'modal'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# byom
|
|
44
|
+
|
|
45
|
+
Bring your own model to Claude Code and other coding agents. byom deploys
|
|
46
|
+
[SGLang](https://github.com/sgl-project/sglang) on Modal or Docker and puts a small proxy in front
|
|
47
|
+
of it that smooths over the few places where Claude Code and SGLang disagree.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install 'byom[modal]'
|
|
51
|
+
byom deploy modal --profile qwen3-coder-30b
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`deploy` prints the environment variables for Claude Code:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export ANTHROPIC_BASE_URL=https://<you>--byom-qwen3-coder-30b-proxy.us-east.modal.direct
|
|
58
|
+
export ANTHROPIC_AUTH_TOKEN=sk-byom-...
|
|
59
|
+
export ANTHROPIC_MODEL=qwen3-coder
|
|
60
|
+
...
|
|
61
|
+
claude
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Requests go straight from Claude Code to your deployment, so nothing goes to Anthropic. You pay
|
|
65
|
+
only for the GPU.
|
|
66
|
+
|
|
67
|
+
## Targets
|
|
68
|
+
|
|
69
|
+
**Modal** (`byom deploy modal`): the GPU server scales to zero after 20 idle minutes, and a
|
|
70
|
+
small always-on CPU proxy keeps the URL stable. The first request after idle waits for the GPU to
|
|
71
|
+
boot (about 4 minutes with cached weights) instead of failing. Needs `modal setup` first.
|
|
72
|
+
|
|
73
|
+
**Docker** (`byom deploy docker`): SGLang and the proxy as a Compose project on an NVIDIA
|
|
74
|
+
machine, reachable at `http://127.0.0.1:8080`. Use `--context <docker context>` to deploy to a
|
|
75
|
+
remote GPU box from your laptop.
|
|
76
|
+
|
|
77
|
+
**Your own SGLang server**: `byom serve --upstream http://localhost:30000 --drop-thinking`.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
byom list # deployments and profiles
|
|
81
|
+
byom env NAME # print the Claude Code settings again
|
|
82
|
+
byom logs NAME -f
|
|
83
|
+
byom down NAME
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Gated models need `HF_TOKEN` set when you deploy.
|
|
87
|
+
|
|
88
|
+
## What the proxy changes
|
|
89
|
+
|
|
90
|
+
Everything is forwarded to SGLang byte for byte, except:
|
|
91
|
+
|
|
92
|
+
- `thinking` is dropped for models served without a reasoning parser (Claude Code always sends
|
|
93
|
+
it; SGLang rejects it).
|
|
94
|
+
- Claude Code's per-request attribution line is removed from the system prompt so SGLang's prefix
|
|
95
|
+
cache works.
|
|
96
|
+
- `x-api-key` is also sent as `Authorization: Bearer`, which is what SGLang checks.
|
|
97
|
+
- While the backend is starting, 503s and refused connections are retried instead of returned.
|
|
98
|
+
|
|
99
|
+
## Profiles
|
|
100
|
+
|
|
101
|
+
A profile is a YAML file naming the model, the SGLang image and flags, and the GPU:
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
name: qwen3-coder-30b
|
|
105
|
+
model: Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8
|
|
106
|
+
revision: dcaee4d4dfc5ee71ad501f01f530e5652438fde0
|
|
107
|
+
image: lmsysorg/sglang:v0.5.23-runtime
|
|
108
|
+
served_name: qwen3-coder
|
|
109
|
+
gpu: H100:1
|
|
110
|
+
args:
|
|
111
|
+
tool_call_parser: qwen3_coder
|
|
112
|
+
context_length: 131072
|
|
113
|
+
drop_thinking: true
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Pass your own with `--profile path/to/model.yaml`. The model needs an SGLang
|
|
117
|
+
`--tool-call-parser`, since Claude Code does everything through tool calls.
|
|
118
|
+
|
|
119
|
+
## Using it from code
|
|
120
|
+
|
|
121
|
+
The same URL serves the OpenAI API under `/v1`, so the OpenAI SDK, Cursor and most other tools work
|
|
122
|
+
too, including streaming, structured outputs and tool calls:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from openai import OpenAI
|
|
126
|
+
from byom.deploy import Deployment
|
|
127
|
+
|
|
128
|
+
dep = Deployment.load("qwen3-coder-30b")
|
|
129
|
+
client = OpenAI(base_url=f"{dep.url}/v1", api_key=dep.api_key, timeout=900)
|
|
130
|
+
|
|
131
|
+
for chunk in client.chat.completions.create(
|
|
132
|
+
model=dep.model, stream=True,
|
|
133
|
+
messages=[{"role": "user", "content": "Explain Python's GIL in two sentences."}],
|
|
134
|
+
):
|
|
135
|
+
if chunk.choices and chunk.choices[0].delta.content:
|
|
136
|
+
print(chunk.choices[0].delta.content, end="")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
[docs/usage.md](https://github.com/shyamsn97/byom/blob/main/docs/usage.md) covers the OpenAI and Anthropic SDKs, structured outputs, tool
|
|
140
|
+
calls, curl and Cursor. Runnable versions are in [examples/](https://github.com/shyamsn97/byom/tree/main/examples):
|
|
141
|
+
|
|
142
|
+
- [`claude_code_qwen.sh`](https://github.com/shyamsn97/byom/blob/main/examples/claude_code_qwen.sh): deploy, then have Claude Code write and
|
|
143
|
+
test a small program.
|
|
144
|
+
- [`openai_sdk.py`](https://github.com/shyamsn97/byom/blob/main/examples/openai_sdk.py): chat, streaming, structured outputs, JSON mode, tool
|
|
145
|
+
calls.
|
|
146
|
+
- [`anthropic_sdk.py`](https://github.com/shyamsn97/byom/blob/main/examples/anthropic_sdk.py): messages, streaming, tool use.
|
|
147
|
+
- [`d1_snake.py`](https://github.com/shyamsn97/byom/blob/main/examples/d1_snake.py): LiquidAI's
|
|
148
|
+
d1-2B decision model playing snake from rendered frames on a Modal GPU
|
|
149
|
+
(`modal run examples/d1_snake.py`). d1 doesn't generate text, so it runs in Transformers
|
|
150
|
+
rather than through byom.
|
|
151
|
+
|
|
152
|
+
`make live NAME=<deployment>` runs all of these checks against a deployment as tests.
|
|
153
|
+
|
|
154
|
+
## Agent skill
|
|
155
|
+
|
|
156
|
+
[`skills/byom/SKILL.md`](https://github.com/shyamsn97/byom/blob/main/skills/byom/SKILL.md) teaches
|
|
157
|
+
coding agents to deploy and connect to byom. Copy the `skills/byom` folder into
|
|
158
|
+
`~/.claude/skills/` for Claude Code or `~/.cursor/skills/` for Cursor.
|
|
159
|
+
|
|
160
|
+
## Development
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
make install # uv sync
|
|
164
|
+
make check # ruff, mypy, pytest
|
|
165
|
+
make live NAME=qwen3-coder-30b # end-to-end tests against a real deployment
|
|
166
|
+
make bump PART=minor # bump the version in pyproject.toml (patch, minor or major)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
To release, commit the bump and publish a GitHub release tagged `v<version>`; the publish
|
|
170
|
+
workflow checks the tag matches and uploads to PyPI.
|
byom-0.2.0/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# byom
|
|
2
|
+
|
|
3
|
+
Bring your own model to Claude Code and other coding agents. byom deploys
|
|
4
|
+
[SGLang](https://github.com/sgl-project/sglang) on Modal or Docker and puts a small proxy in front
|
|
5
|
+
of it that smooths over the few places where Claude Code and SGLang disagree.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install 'byom[modal]'
|
|
9
|
+
byom deploy modal --profile qwen3-coder-30b
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`deploy` prints the environment variables for Claude Code:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
export ANTHROPIC_BASE_URL=https://<you>--byom-qwen3-coder-30b-proxy.us-east.modal.direct
|
|
16
|
+
export ANTHROPIC_AUTH_TOKEN=sk-byom-...
|
|
17
|
+
export ANTHROPIC_MODEL=qwen3-coder
|
|
18
|
+
...
|
|
19
|
+
claude
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requests go straight from Claude Code to your deployment, so nothing goes to Anthropic. You pay
|
|
23
|
+
only for the GPU.
|
|
24
|
+
|
|
25
|
+
## Targets
|
|
26
|
+
|
|
27
|
+
**Modal** (`byom deploy modal`): the GPU server scales to zero after 20 idle minutes, and a
|
|
28
|
+
small always-on CPU proxy keeps the URL stable. The first request after idle waits for the GPU to
|
|
29
|
+
boot (about 4 minutes with cached weights) instead of failing. Needs `modal setup` first.
|
|
30
|
+
|
|
31
|
+
**Docker** (`byom deploy docker`): SGLang and the proxy as a Compose project on an NVIDIA
|
|
32
|
+
machine, reachable at `http://127.0.0.1:8080`. Use `--context <docker context>` to deploy to a
|
|
33
|
+
remote GPU box from your laptop.
|
|
34
|
+
|
|
35
|
+
**Your own SGLang server**: `byom serve --upstream http://localhost:30000 --drop-thinking`.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
byom list # deployments and profiles
|
|
39
|
+
byom env NAME # print the Claude Code settings again
|
|
40
|
+
byom logs NAME -f
|
|
41
|
+
byom down NAME
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Gated models need `HF_TOKEN` set when you deploy.
|
|
45
|
+
|
|
46
|
+
## What the proxy changes
|
|
47
|
+
|
|
48
|
+
Everything is forwarded to SGLang byte for byte, except:
|
|
49
|
+
|
|
50
|
+
- `thinking` is dropped for models served without a reasoning parser (Claude Code always sends
|
|
51
|
+
it; SGLang rejects it).
|
|
52
|
+
- Claude Code's per-request attribution line is removed from the system prompt so SGLang's prefix
|
|
53
|
+
cache works.
|
|
54
|
+
- `x-api-key` is also sent as `Authorization: Bearer`, which is what SGLang checks.
|
|
55
|
+
- While the backend is starting, 503s and refused connections are retried instead of returned.
|
|
56
|
+
|
|
57
|
+
## Profiles
|
|
58
|
+
|
|
59
|
+
A profile is a YAML file naming the model, the SGLang image and flags, and the GPU:
|
|
60
|
+
|
|
61
|
+
```yaml
|
|
62
|
+
name: qwen3-coder-30b
|
|
63
|
+
model: Qwen/Qwen3-Coder-30B-A3B-Instruct-FP8
|
|
64
|
+
revision: dcaee4d4dfc5ee71ad501f01f530e5652438fde0
|
|
65
|
+
image: lmsysorg/sglang:v0.5.23-runtime
|
|
66
|
+
served_name: qwen3-coder
|
|
67
|
+
gpu: H100:1
|
|
68
|
+
args:
|
|
69
|
+
tool_call_parser: qwen3_coder
|
|
70
|
+
context_length: 131072
|
|
71
|
+
drop_thinking: true
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Pass your own with `--profile path/to/model.yaml`. The model needs an SGLang
|
|
75
|
+
`--tool-call-parser`, since Claude Code does everything through tool calls.
|
|
76
|
+
|
|
77
|
+
## Using it from code
|
|
78
|
+
|
|
79
|
+
The same URL serves the OpenAI API under `/v1`, so the OpenAI SDK, Cursor and most other tools work
|
|
80
|
+
too, including streaming, structured outputs and tool calls:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from openai import OpenAI
|
|
84
|
+
from byom.deploy import Deployment
|
|
85
|
+
|
|
86
|
+
dep = Deployment.load("qwen3-coder-30b")
|
|
87
|
+
client = OpenAI(base_url=f"{dep.url}/v1", api_key=dep.api_key, timeout=900)
|
|
88
|
+
|
|
89
|
+
for chunk in client.chat.completions.create(
|
|
90
|
+
model=dep.model, stream=True,
|
|
91
|
+
messages=[{"role": "user", "content": "Explain Python's GIL in two sentences."}],
|
|
92
|
+
):
|
|
93
|
+
if chunk.choices and chunk.choices[0].delta.content:
|
|
94
|
+
print(chunk.choices[0].delta.content, end="")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
[docs/usage.md](https://github.com/shyamsn97/byom/blob/main/docs/usage.md) covers the OpenAI and Anthropic SDKs, structured outputs, tool
|
|
98
|
+
calls, curl and Cursor. Runnable versions are in [examples/](https://github.com/shyamsn97/byom/tree/main/examples):
|
|
99
|
+
|
|
100
|
+
- [`claude_code_qwen.sh`](https://github.com/shyamsn97/byom/blob/main/examples/claude_code_qwen.sh): deploy, then have Claude Code write and
|
|
101
|
+
test a small program.
|
|
102
|
+
- [`openai_sdk.py`](https://github.com/shyamsn97/byom/blob/main/examples/openai_sdk.py): chat, streaming, structured outputs, JSON mode, tool
|
|
103
|
+
calls.
|
|
104
|
+
- [`anthropic_sdk.py`](https://github.com/shyamsn97/byom/blob/main/examples/anthropic_sdk.py): messages, streaming, tool use.
|
|
105
|
+
- [`d1_snake.py`](https://github.com/shyamsn97/byom/blob/main/examples/d1_snake.py): LiquidAI's
|
|
106
|
+
d1-2B decision model playing snake from rendered frames on a Modal GPU
|
|
107
|
+
(`modal run examples/d1_snake.py`). d1 doesn't generate text, so it runs in Transformers
|
|
108
|
+
rather than through byom.
|
|
109
|
+
|
|
110
|
+
`make live NAME=<deployment>` runs all of these checks against a deployment as tests.
|
|
111
|
+
|
|
112
|
+
## Agent skill
|
|
113
|
+
|
|
114
|
+
[`skills/byom/SKILL.md`](https://github.com/shyamsn97/byom/blob/main/skills/byom/SKILL.md) teaches
|
|
115
|
+
coding agents to deploy and connect to byom. Copy the `skills/byom` folder into
|
|
116
|
+
`~/.claude/skills/` for Claude Code or `~/.cursor/skills/` for Cursor.
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
make install # uv sync
|
|
122
|
+
make check # ruff, mypy, pytest
|
|
123
|
+
make live NAME=qwen3-coder-30b # end-to-end tests against a real deployment
|
|
124
|
+
make bump PART=minor # bump the version in pyproject.toml (patch, minor or major)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
To release, commit the bump and publish a GitHub release tagged `v<version>`; the publish
|
|
128
|
+
workflow checks the tag matches and uploads to PyPI.
|
byom-0.2.0/byom/cli.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from types import ModuleType
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from byom import proxy
|
|
9
|
+
from byom.deploy import DeployError, Deployment, names
|
|
10
|
+
from byom.profiles import list_profiles, load_profile
|
|
11
|
+
|
|
12
|
+
app = typer.Typer(no_args_is_help=True, add_completion=False, pretty_exceptions_enable=False,
|
|
13
|
+
help="Deploy SGLang and put Claude Code (and friends) in front of it.")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.command()
|
|
17
|
+
def serve(
|
|
18
|
+
upstream: Annotated[str, typer.Option(help="SGLang URL, e.g. http://localhost:30000")],
|
|
19
|
+
host: str = "127.0.0.1",
|
|
20
|
+
port: int = 8080,
|
|
21
|
+
drop_thinking: Annotated[bool, typer.Option(
|
|
22
|
+
help="Drop `thinking` (for models served without a reasoning parser).")] = False,
|
|
23
|
+
hold: Annotated[float, typer.Option(
|
|
24
|
+
help="Seconds to retry while the upstream is starting (503 / refused).")] = 0,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Run the proxy in front of an SGLang server."""
|
|
27
|
+
proxy.serve(upstream, host=host, port=port, drop_thinking=drop_thinking, hold_s=hold)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@app.command()
|
|
31
|
+
def deploy(
|
|
32
|
+
target: Annotated[str, typer.Argument(help="docker or modal")],
|
|
33
|
+
profile: Annotated[str, typer.Option(help="Profile name or path to a .yaml")],
|
|
34
|
+
name: Annotated[str | None, typer.Option(help="Defaults to the profile name.")] = None,
|
|
35
|
+
context: Annotated[str | None, typer.Option(help="docker: remote Docker context.")] = None,
|
|
36
|
+
port: Annotated[int, typer.Option(help="docker: host port for the proxy.")] = 8080,
|
|
37
|
+
public: Annotated[bool, typer.Option(help="docker: listen on 0.0.0.0.")] = False,
|
|
38
|
+
region: Annotated[str, typer.Option(help="modal: routing region.")] = "us-east",
|
|
39
|
+
) -> None:
|
|
40
|
+
"""Deploy SGLang + the proxy, then print the Claude Code settings."""
|
|
41
|
+
prof = load_profile(profile)
|
|
42
|
+
name = name or prof.name
|
|
43
|
+
if target == "docker":
|
|
44
|
+
from byom.deploy import docker
|
|
45
|
+
|
|
46
|
+
dep = docker.up(prof, name, context=context, port=port, public=public)
|
|
47
|
+
elif target == "modal":
|
|
48
|
+
from byom.deploy import modal
|
|
49
|
+
|
|
50
|
+
dep = modal.up(prof, name, region=region)
|
|
51
|
+
else:
|
|
52
|
+
raise DeployError(f"unknown target {target!r}; use docker or modal")
|
|
53
|
+
typer.secho(f"\n{dep.name} is up at {dep.url}", fg="green")
|
|
54
|
+
typer.echo("The first request after idle waits for the GPU to start (a few minutes).")
|
|
55
|
+
typer.echo("Claude Code settings (also: `byom env " + dep.name + "`):\n")
|
|
56
|
+
typer.echo(dep.claude_code_env())
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@app.command()
|
|
60
|
+
def env(name: str) -> None:
|
|
61
|
+
"""Print the Claude Code environment for a deployment."""
|
|
62
|
+
typer.echo(Deployment.load(name).claude_code_env())
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@app.command()
|
|
66
|
+
def down(name: str) -> None:
|
|
67
|
+
"""Stop a deployment and forget it."""
|
|
68
|
+
dep = Deployment.load(name)
|
|
69
|
+
_target(dep).down(dep)
|
|
70
|
+
dep.remove()
|
|
71
|
+
typer.echo(f"stopped {name}")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@app.command()
|
|
75
|
+
def logs(name: str, follow: Annotated[bool, typer.Option("--follow", "-f")] = False) -> None:
|
|
76
|
+
"""Show deployment logs."""
|
|
77
|
+
dep = Deployment.load(name)
|
|
78
|
+
for line in _target(dep).logs(dep, follow):
|
|
79
|
+
typer.echo(line, nl=False)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@app.command("list")
|
|
83
|
+
def list_() -> None:
|
|
84
|
+
"""Saved deployments and bundled profiles."""
|
|
85
|
+
for n in names():
|
|
86
|
+
dep = Deployment.load(n)
|
|
87
|
+
typer.echo(f"{n:24} {dep.target:7} {dep.url}")
|
|
88
|
+
typer.echo(f"profiles: {', '.join(list_profiles())}")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _target(dep: Deployment) -> ModuleType:
|
|
92
|
+
if dep.target == "docker":
|
|
93
|
+
from byom.deploy import docker
|
|
94
|
+
|
|
95
|
+
return docker
|
|
96
|
+
from byom.deploy import modal
|
|
97
|
+
|
|
98
|
+
return modal
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def main() -> None:
|
|
102
|
+
try:
|
|
103
|
+
app()
|
|
104
|
+
except (DeployError, ValueError) as e:
|
|
105
|
+
typer.secho(f"error: {e}", fg="red", err=True)
|
|
106
|
+
raise SystemExit(1) from None
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Deployments (SGLang + proxy on Docker or Modal), each saved as a small JSON record."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import secrets
|
|
8
|
+
import shlex
|
|
9
|
+
from dataclasses import asdict, dataclass, field
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
STATE_DIR = Path(os.environ.get("XDG_STATE_HOME", "~/.local/state")).expanduser() / "byom"
|
|
14
|
+
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DeployError(Exception):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class Deployment:
|
|
23
|
+
name: str
|
|
24
|
+
target: str
|
|
25
|
+
url: str
|
|
26
|
+
api_key: str = field(repr=False)
|
|
27
|
+
model: str
|
|
28
|
+
extra: dict[str, Any] = field(default_factory=dict)
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def dir(self) -> Path:
|
|
32
|
+
return STATE_DIR / self.name
|
|
33
|
+
|
|
34
|
+
def save(self) -> None:
|
|
35
|
+
self.dir.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
path = self.dir / "deployment.json"
|
|
37
|
+
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
|
38
|
+
with os.fdopen(fd, "w") as f:
|
|
39
|
+
json.dump(asdict(self), f, indent=2)
|
|
40
|
+
|
|
41
|
+
@classmethod
|
|
42
|
+
def load(cls, name: str) -> Deployment:
|
|
43
|
+
path = STATE_DIR / name / "deployment.json"
|
|
44
|
+
if not path.is_file():
|
|
45
|
+
have = ", ".join(names()) or "none"
|
|
46
|
+
raise DeployError(f"no deployment named {name!r} (have: {have})")
|
|
47
|
+
return cls(**json.loads(path.read_text()))
|
|
48
|
+
|
|
49
|
+
def remove(self) -> None:
|
|
50
|
+
(self.dir / "deployment.json").unlink(missing_ok=True)
|
|
51
|
+
|
|
52
|
+
def claude_code_env(self) -> str:
|
|
53
|
+
env = {
|
|
54
|
+
"ANTHROPIC_BASE_URL": self.url,
|
|
55
|
+
"ANTHROPIC_AUTH_TOKEN": self.api_key,
|
|
56
|
+
"ANTHROPIC_MODEL": self.model,
|
|
57
|
+
"ANTHROPIC_DEFAULT_OPUS_MODEL": self.model,
|
|
58
|
+
"ANTHROPIC_DEFAULT_SONNET_MODEL": self.model,
|
|
59
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL": self.model,
|
|
60
|
+
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
|
|
61
|
+
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
|
|
62
|
+
"API_TIMEOUT_MS": "3000000",
|
|
63
|
+
}
|
|
64
|
+
return "\n".join(f"export {k}={shlex.quote(v)}" for k, v in env.items())
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def names() -> list[str]:
|
|
68
|
+
if not STATE_DIR.is_dir():
|
|
69
|
+
return []
|
|
70
|
+
return sorted(p.parent.name for p in STATE_DIR.glob("*/deployment.json"))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def api_key_for(name: str) -> str:
|
|
74
|
+
"""Reuse the key on redeploy so clients keep working."""
|
|
75
|
+
try:
|
|
76
|
+
return Deployment.load(name).api_key
|
|
77
|
+
except DeployError:
|
|
78
|
+
return "sk-byom-" + secrets.token_urlsafe(24)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def local_checkout() -> Path | None:
|
|
82
|
+
"""The repo root when running from a git checkout (the proxy is then built from source)."""
|
|
83
|
+
return REPO_ROOT if (REPO_ROOT / "docker" / "proxy.Dockerfile").is_file() else None
|