jupyterlab-biolm 1.1.0__tar.gz → 1.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.
- jupyterlab_biolm-1.2.0/Dockerfile.visual-test +16 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/PKG-INFO +2 -1
- jupyterlab_biolm-1.2.0/VERSIONING.md +263 -0
- jupyterlab_biolm-1.2.0/docker-compose.visual-test.yml +16 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/jupyterlab_biolm/serverextension.py +130 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/package-lock.json +2 -2
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/package.json +1 -1
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/pyproject.toml +1 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/setup.py +1 -0
- jupyterlab_biolm-1.2.0/src/api/client.ts +363 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/api/types.ts +9 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/components/ModelsTab.tsx +41 -7
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/components/SettingsTab.tsx +37 -3
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/index.ts +24 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/services/codeInsertion.ts +50 -2
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/widget.tsx +1 -1
- jupyterlab_biolm-1.1.0/src/api/client.ts +0 -197
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/.github/workflows/ci.yml +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/.github/workflows/publish.yml +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/.gitignore +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/CICD.md +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/Makefile +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/README.md +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/REQUIREMENTS.md +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/check_extension.js +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/clear_cache_instructions.md +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/diagnose_extension.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/install.json +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/jupyter-config/server-config/jupyterlab-biolm.json +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/jupyterlab_biolm/__init__.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/jupyterlab_biolm/_hatchling.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/schema/plugin.json +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/check_server_status.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/prepare_wheel.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/start_test_server.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/test_deployment.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/test_endpoint.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/test_local.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/test_pypi_install.sh +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/scripts/wait_for_server.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/components/OperationsTab.tsx +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/data/operations.ts +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/services/localStorage.ts +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/src/services/settings.ts +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/style/index.css +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/test_api.html +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/test_extension.py +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/tsconfig.json +0 -0
- {jupyterlab_biolm-1.1.0 → jupyterlab_biolm-1.2.0}/webpack.config.js +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
FROM jupyter/scipy-notebook:latest
|
|
2
|
+
|
|
3
|
+
USER root
|
|
4
|
+
|
|
5
|
+
# Install build tools
|
|
6
|
+
RUN pip install --no-cache-dir build wheel
|
|
7
|
+
|
|
8
|
+
# Copy and install the latest wheel
|
|
9
|
+
COPY dist/jupyterlab_biolm-1.1.0-py3-none-any.whl /tmp/
|
|
10
|
+
RUN pip install --no-cache-dir /tmp/jupyterlab_biolm-1.1.0-py3-none-any.whl
|
|
11
|
+
|
|
12
|
+
USER $NB_UID
|
|
13
|
+
|
|
14
|
+
# Expose JupyterLab port
|
|
15
|
+
EXPOSE 8888
|
|
16
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jupyterlab-biolm
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: JupyterLab extension for BioLM API integration
|
|
5
5
|
Project-URL: Homepage, https://github.com/BioLM/jupyterlab-biolm
|
|
6
6
|
Project-URL: Repository, https://github.com/BioLM/jupyterlab-biolm
|
|
@@ -22,6 +22,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.10
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.11
|
|
24
24
|
Requires-Python: >=3.8
|
|
25
|
+
Requires-Dist: biolmai
|
|
25
26
|
Requires-Dist: jupyter-server>=2.0.0
|
|
26
27
|
Requires-Dist: jupyterlab<5,>=4.0.0
|
|
27
28
|
Provides-Extra: dev
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Version Management Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This project uses **semantic-release** to automatically manage versions based on [Conventional Commits](https://www.conventionalcommits.org/).
|
|
6
|
+
|
|
7
|
+
**Key principles:**
|
|
8
|
+
- **Production versions**: Let semantic-release handle them automatically
|
|
9
|
+
- **TestPyPI versions**: Use `-rc` (release candidate) suffixes (e.g., `1.0.9-rc.1`)
|
|
10
|
+
- **Local testing**: Don't bump version, just test with current version
|
|
11
|
+
|
|
12
|
+
## How It Works
|
|
13
|
+
|
|
14
|
+
1. **Commit with conventional format** (e.g., `feat:`, `fix:`, `BREAKING:`)
|
|
15
|
+
2. **Push to main branch**
|
|
16
|
+
3. **CI runs semantic-release** which:
|
|
17
|
+
- Analyzes commit messages
|
|
18
|
+
- Determines version bump (major/minor/patch)
|
|
19
|
+
- Updates `package.json` version
|
|
20
|
+
- Creates git tag (e.g., `v1.0.12`)
|
|
21
|
+
- Pushes tag to GitHub
|
|
22
|
+
4. **Python version syncs automatically** via `hatch-nodejs-version` from `package.json`
|
|
23
|
+
|
|
24
|
+
## Commit Message Format
|
|
25
|
+
|
|
26
|
+
| Commit Type | Version Bump | Example |
|
|
27
|
+
|------------|--------------|---------|
|
|
28
|
+
| `feat: ...` | **Minor** (1.0.11 → 1.1.0) | `feat: add new model browser` |
|
|
29
|
+
| `fix: ...` | **Patch** (1.0.11 → 1.0.12) | `fix: resolve CORS issue` |
|
|
30
|
+
| `BREAKING: ...` | **Major** (1.0.11 → 2.0.0) | `BREAKING: change API interface` |
|
|
31
|
+
| No prefix | **None** | `docs: update README` |
|
|
32
|
+
|
|
33
|
+
## ❌ What NOT to Do
|
|
34
|
+
|
|
35
|
+
**NEVER manually edit the version in `package.json`** when using semantic-release. This causes mismatches:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# ❌ BAD - Don't do this!
|
|
39
|
+
# Manually editing package.json version
|
|
40
|
+
# This will cause semantic-release to create a different tag
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## ✅ Correct Workflow
|
|
44
|
+
|
|
45
|
+
### For Regular Releases
|
|
46
|
+
|
|
47
|
+
1. **Make your changes**
|
|
48
|
+
2. **Commit with conventional format:**
|
|
49
|
+
```bash
|
|
50
|
+
git commit -m "fix: remove server extension dependency"
|
|
51
|
+
git push origin main
|
|
52
|
+
```
|
|
53
|
+
3. **Wait for CI to complete:**
|
|
54
|
+
- Tests run
|
|
55
|
+
- semantic-release analyzes commits
|
|
56
|
+
- Version bumped in `package.json` (if needed)
|
|
57
|
+
- Git tag created and pushed
|
|
58
|
+
4. **Publish to TestPyPI/PyPI:**
|
|
59
|
+
- Use the version that semantic-release created
|
|
60
|
+
- Or wait for the publish workflow to run automatically
|
|
61
|
+
|
|
62
|
+
### For Local Testing
|
|
63
|
+
|
|
64
|
+
**You don't need to bump the version for local testing!** Just test with the current version:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Make your changes
|
|
68
|
+
vim src/api/client.ts
|
|
69
|
+
|
|
70
|
+
# Build and test locally (version doesn't matter for local testing)
|
|
71
|
+
python3 -m build
|
|
72
|
+
# Test the built package
|
|
73
|
+
|
|
74
|
+
# Commit your changes (without any version bump)
|
|
75
|
+
git add src/api/client.ts
|
|
76
|
+
git commit -m "fix: call BioLM API directly from client"
|
|
77
|
+
git push origin main
|
|
78
|
+
# semantic-release will handle the version bump
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### For TestPyPI Publishing (Recommended: Use -rc suffixes)
|
|
82
|
+
|
|
83
|
+
**Best Practice: Always use `-rc` (release candidate) suffixes for TestPyPI**
|
|
84
|
+
|
|
85
|
+
This ensures TestPyPI versions don't conflict with semantic-release's production versions:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 1. Make your changes and commit
|
|
89
|
+
git commit -m "fix: some bug fix"
|
|
90
|
+
|
|
91
|
+
# 2. Bump to release candidate version
|
|
92
|
+
npm version 1.0.9-rc.1 --no-git-tag-version
|
|
93
|
+
git add package.json
|
|
94
|
+
git commit -m "chore: bump to 1.0.9-rc.1 for TestPyPI"
|
|
95
|
+
|
|
96
|
+
# 3. Build and publish to TestPyPI
|
|
97
|
+
python3 -m build
|
|
98
|
+
python3 -m twine upload --repository testpypi dist/jupyterlab_biolm-1.0.9-rc.1*
|
|
99
|
+
|
|
100
|
+
# 4. Push commits (semantic-release will create 1.0.9 when ready)
|
|
101
|
+
git push origin main
|
|
102
|
+
# When semantic-release runs, it will create v1.0.9 (which is > 1.0.9-rc.1)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Why `-rc` suffixes?**
|
|
106
|
+
- ✅ TestPyPI versions are clearly marked as pre-release
|
|
107
|
+
- ✅ semantic-release can still create the final version (1.0.9 > 1.0.9-rc.1)
|
|
108
|
+
- ✅ No version conflicts
|
|
109
|
+
- ✅ Standard practice in the industry
|
|
110
|
+
|
|
111
|
+
**Alternative: Wait for semantic-release**
|
|
112
|
+
```bash
|
|
113
|
+
# Just push your commit and wait
|
|
114
|
+
git push origin main
|
|
115
|
+
# Wait for CI/semantic-release to create the tag
|
|
116
|
+
git fetch --tags
|
|
117
|
+
# Use the version from the tag for publishing
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Current Version Status
|
|
121
|
+
|
|
122
|
+
To check the current version:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Check package.json
|
|
126
|
+
cat package.json | grep '"version"'
|
|
127
|
+
|
|
128
|
+
# Check latest git tag
|
|
129
|
+
git describe --tags --abbrev=0
|
|
130
|
+
|
|
131
|
+
# Check what semantic-release will do (dry run)
|
|
132
|
+
npx semantic-release --dry-run
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Troubleshooting Version Mismatches
|
|
136
|
+
|
|
137
|
+
If you see a mismatch between `package.json` and git tags:
|
|
138
|
+
|
|
139
|
+
1. **Check what semantic-release created:**
|
|
140
|
+
```bash
|
|
141
|
+
git fetch --tags
|
|
142
|
+
git tag --sort=-version:refname | head -5
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
2. **Align versions:**
|
|
146
|
+
- If `package.json` is ahead: Let semantic-release handle it on the next commit
|
|
147
|
+
- If tags are ahead: Pull the semantic-release commit that updated `package.json`
|
|
148
|
+
|
|
149
|
+
3. **Reset if needed:**
|
|
150
|
+
```bash
|
|
151
|
+
# Only if absolutely necessary - this is destructive!
|
|
152
|
+
# Pull the version from the latest tag
|
|
153
|
+
git checkout v1.0.8 -- package.json
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Best Practices
|
|
157
|
+
|
|
158
|
+
1. ✅ **Always use conventional commits** (`feat:`, `fix:`, etc.)
|
|
159
|
+
2. ✅ **Let semantic-release handle all production version bumps**
|
|
160
|
+
3. ✅ **Publish to TestPyPI/PyPI after semantic-release creates the tag**
|
|
161
|
+
4. ✅ **Don't bump version for local testing** (just test with current version)
|
|
162
|
+
5. ✅ **Use `-rc` suffixes for TestPyPI** (e.g., `1.0.9-rc.1`) - this is the standard practice
|
|
163
|
+
6. ❌ **Never manually edit `package.json` version for production releases** (let semantic-release do it)
|
|
164
|
+
7. ❌ **Never create git tags manually** (let semantic-release do it)
|
|
165
|
+
8. ❌ **Never bump version just to revert it** (that workflow doesn't make sense)
|
|
166
|
+
|
|
167
|
+
## Example Workflows
|
|
168
|
+
|
|
169
|
+
### Standard Release Workflow
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# 1. Make changes
|
|
173
|
+
vim src/api/client.ts
|
|
174
|
+
|
|
175
|
+
# 2. Commit with conventional format
|
|
176
|
+
git add src/api/client.ts
|
|
177
|
+
git commit -m "fix: call BioLM API directly from client"
|
|
178
|
+
|
|
179
|
+
# 3. Push
|
|
180
|
+
git push origin main
|
|
181
|
+
|
|
182
|
+
# 4. Wait for CI
|
|
183
|
+
# - CI runs tests
|
|
184
|
+
# - semantic-release creates v1.0.12 tag
|
|
185
|
+
# - package.json updated to 1.0.12
|
|
186
|
+
|
|
187
|
+
# 5. Publish (if needed)
|
|
188
|
+
# Use the version from the tag: 1.0.12
|
|
189
|
+
python3 -m build
|
|
190
|
+
python3 -m twine upload --repository testpypi dist/jupyterlab_biolm-1.0.12*
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Local Testing Workflow
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# 1. Make changes
|
|
197
|
+
vim src/api/client.ts
|
|
198
|
+
|
|
199
|
+
# 2. Build and test locally (no version bump needed!)
|
|
200
|
+
python3 -m build
|
|
201
|
+
# Test the built package locally
|
|
202
|
+
|
|
203
|
+
# 3. Commit your changes (without any version bump)
|
|
204
|
+
git add src/api/client.ts
|
|
205
|
+
git commit -m "fix: call BioLM API directly from client"
|
|
206
|
+
|
|
207
|
+
# 4. Push (semantic-release will create the version)
|
|
208
|
+
git push origin main
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### TestPyPI Publishing Workflow (using -rc suffixes)
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Recommended workflow for TestPyPI publishing:
|
|
215
|
+
|
|
216
|
+
# 1. Make your changes and commit
|
|
217
|
+
git add src/api/client.ts
|
|
218
|
+
git commit -m "fix: call BioLM API directly from client"
|
|
219
|
+
|
|
220
|
+
# 2. Bump to release candidate version
|
|
221
|
+
npm version 1.0.9-rc.1 --no-git-tag-version
|
|
222
|
+
git add package.json
|
|
223
|
+
git commit -m "chore: bump to 1.0.9-rc.1 for TestPyPI"
|
|
224
|
+
|
|
225
|
+
# 3. Build and publish to TestPyPI
|
|
226
|
+
python3 -m build
|
|
227
|
+
python3 -m twine upload --repository testpypi dist/jupyterlab_biolm-1.0.9-rc.1*
|
|
228
|
+
|
|
229
|
+
# 4. Push commits
|
|
230
|
+
git push origin main
|
|
231
|
+
|
|
232
|
+
# 5. semantic-release will create 1.0.9 when it runs
|
|
233
|
+
# (1.0.9 > 1.0.9-rc.1, so no conflict)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Configuration
|
|
237
|
+
|
|
238
|
+
The semantic-release configuration is in `package.json`:
|
|
239
|
+
|
|
240
|
+
```json
|
|
241
|
+
{
|
|
242
|
+
"release": {
|
|
243
|
+
"branches": ["main", "master"],
|
|
244
|
+
"plugins": [
|
|
245
|
+
"@semantic-release/commit-analyzer",
|
|
246
|
+
"@semantic-release/release-notes-generator",
|
|
247
|
+
["@semantic-release/npm", { "npmPublish": false }],
|
|
248
|
+
["@semantic-release/git", {
|
|
249
|
+
"assets": ["package.json"],
|
|
250
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]"
|
|
251
|
+
}]
|
|
252
|
+
]
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
This configuration:
|
|
258
|
+
- Analyzes commits for version bumps
|
|
259
|
+
- Updates `package.json` with new version
|
|
260
|
+
- Creates git tag
|
|
261
|
+
- Commits the version bump back to the repo
|
|
262
|
+
- Skips CI on the version bump commit (to avoid loops)
|
|
263
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
services:
|
|
2
|
+
jupyterlab:
|
|
3
|
+
build:
|
|
4
|
+
context: .
|
|
5
|
+
dockerfile: Dockerfile.visual-test
|
|
6
|
+
ports:
|
|
7
|
+
- "8888:8888"
|
|
8
|
+
volumes:
|
|
9
|
+
- test-notebooks:/home/jovyan/work
|
|
10
|
+
environment:
|
|
11
|
+
- JUPYTER_ENABLE_LAB=yes
|
|
12
|
+
command: jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --ServerApp.token='' --ServerApp.password='' --IdentityProvider.token=''
|
|
13
|
+
|
|
14
|
+
volumes:
|
|
15
|
+
test-notebooks:
|
|
16
|
+
|
|
@@ -81,6 +81,135 @@ class BioLMModelsHandler(APIHandler):
|
|
|
81
81
|
self.finish(json.dumps(error_data))
|
|
82
82
|
|
|
83
83
|
|
|
84
|
+
class BioLMModelDetailsHandler(APIHandler):
|
|
85
|
+
"""Handler for fetching individual model details with code examples"""
|
|
86
|
+
|
|
87
|
+
# Disable XSRF for API endpoints
|
|
88
|
+
def check_xsrf_cookie(self):
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
@tornado.web.authenticated
|
|
92
|
+
def get(self, model_slug):
|
|
93
|
+
"""Fetch model details from BioLM API"""
|
|
94
|
+
try:
|
|
95
|
+
# Get API key from Authorization header or query parameter
|
|
96
|
+
api_key = None
|
|
97
|
+
auth_header = self.request.headers.get('Authorization', '')
|
|
98
|
+
if auth_header.startswith('Bearer '):
|
|
99
|
+
api_key = auth_header[7:]
|
|
100
|
+
else:
|
|
101
|
+
api_key = self.get_query_argument('api_key', None)
|
|
102
|
+
|
|
103
|
+
# Build request to BioLM API with code_examples and exclude_docs_html
|
|
104
|
+
url = f'https://biolm.ai/api/ui/community-api-models/{model_slug}/?code_examples=true&exclude_docs_html=true'
|
|
105
|
+
headers = {
|
|
106
|
+
'Content-Type': 'application/json',
|
|
107
|
+
'User-Agent': 'JupyterLab-BioLM-Extension/0.1.0',
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if api_key:
|
|
111
|
+
headers['Authorization'] = f'Bearer {api_key}'
|
|
112
|
+
|
|
113
|
+
# Make request
|
|
114
|
+
req = Request(url, headers=headers)
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
with urlopen(req, timeout=10) as response:
|
|
118
|
+
data = json.loads(response.read().decode('utf-8'))
|
|
119
|
+
|
|
120
|
+
# Transform example_payload fields into code_examples format
|
|
121
|
+
code_examples = []
|
|
122
|
+
model_slug_from_data = data.get('model_slug', model_slug)
|
|
123
|
+
|
|
124
|
+
# Map action types to their example payload fields
|
|
125
|
+
action_mapping = {
|
|
126
|
+
'predict': 'predictor_example_payload',
|
|
127
|
+
'encode': 'encoder_example_payload',
|
|
128
|
+
'generate': 'generator_example_payload',
|
|
129
|
+
'classify': 'classifier_example_payload',
|
|
130
|
+
'similarity': 'similarity_example_payload',
|
|
131
|
+
'explain': 'explainer_example_payload',
|
|
132
|
+
'transform': 'transformer_example_payload',
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
for action, payload_key in action_mapping.items():
|
|
136
|
+
payload = data.get(payload_key)
|
|
137
|
+
if payload and payload.get('items'):
|
|
138
|
+
items = payload['items']
|
|
139
|
+
|
|
140
|
+
# Determine item type and format
|
|
141
|
+
if isinstance(items, list) and len(items) > 0:
|
|
142
|
+
# Check if items are objects with 'sequence' field
|
|
143
|
+
if isinstance(items[0], dict) and 'sequence' in items[0]:
|
|
144
|
+
sequences = [item['sequence'] for item in items]
|
|
145
|
+
if len(sequences) == 1:
|
|
146
|
+
code = f'result = biolm(entity="{model_slug_from_data}", action="{action}", type="sequence", items="{sequences[0]}")\n\nprint(result)'
|
|
147
|
+
else:
|
|
148
|
+
seq_list = ', '.join([f'"{seq}"' for seq in sequences])
|
|
149
|
+
code = f'result = biolm(entity="{model_slug_from_data}", action="{action}", type="sequence", items=[{seq_list}])\n\nprint(result)'
|
|
150
|
+
else:
|
|
151
|
+
# Handle other item formats
|
|
152
|
+
if len(items) == 1:
|
|
153
|
+
code = f'result = biolm(entity="{model_slug_from_data}", action="{action}", type="sequence", items={json.dumps(items[0])})\n\nprint(result)'
|
|
154
|
+
else:
|
|
155
|
+
code = f'result = biolm(entity="{model_slug_from_data}", action="{action}", type="sequence", items={json.dumps(items)})\n\nprint(result)'
|
|
156
|
+
|
|
157
|
+
code_examples.append({
|
|
158
|
+
'action': action,
|
|
159
|
+
'code': code
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
# Add setup example for environment variable (if API key is provided)
|
|
163
|
+
api_key = None
|
|
164
|
+
auth_header = self.request.headers.get('Authorization', '')
|
|
165
|
+
if auth_header.startswith('Bearer '):
|
|
166
|
+
api_key = auth_header[7:]
|
|
167
|
+
else:
|
|
168
|
+
api_key = self.get_query_argument('api_key', None)
|
|
169
|
+
|
|
170
|
+
if api_key:
|
|
171
|
+
# Add setup example as the first example
|
|
172
|
+
setup_code = f"import os\nos.environ['BIOLMAI_TOKEN'] = 'YOUR_API_KEY_HERE' # Replace with your actual API key"
|
|
173
|
+
code_examples.insert(0, {
|
|
174
|
+
'action': 'setup',
|
|
175
|
+
'code': setup_code
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
# Add code_examples to the response
|
|
179
|
+
if code_examples:
|
|
180
|
+
data['code_examples'] = code_examples
|
|
181
|
+
|
|
182
|
+
self.set_status(200)
|
|
183
|
+
self.set_header('Content-Type', 'application/json')
|
|
184
|
+
self.finish(json.dumps(data))
|
|
185
|
+
except HTTPError as e:
|
|
186
|
+
error_data = {
|
|
187
|
+
'error': True,
|
|
188
|
+
'message': f'API request failed: {e.code} {e.reason}',
|
|
189
|
+
'status': e.code,
|
|
190
|
+
}
|
|
191
|
+
self.set_status(e.code)
|
|
192
|
+
self.set_header('Content-Type', 'application/json')
|
|
193
|
+
self.finish(json.dumps(error_data))
|
|
194
|
+
except URLError as e:
|
|
195
|
+
error_data = {
|
|
196
|
+
'error': True,
|
|
197
|
+
'message': f'Network error: {str(e)}',
|
|
198
|
+
}
|
|
199
|
+
self.set_status(500)
|
|
200
|
+
self.set_header('Content-Type', 'application/json')
|
|
201
|
+
self.finish(json.dumps(error_data))
|
|
202
|
+
|
|
203
|
+
except Exception as e:
|
|
204
|
+
error_data = {
|
|
205
|
+
'error': True,
|
|
206
|
+
'message': f'Server error: {str(e)}',
|
|
207
|
+
}
|
|
208
|
+
self.set_status(500)
|
|
209
|
+
self.set_header('Content-Type', 'application/json')
|
|
210
|
+
self.finish(json.dumps(error_data))
|
|
211
|
+
|
|
212
|
+
|
|
84
213
|
class BioLMTestConnectionHandler(APIHandler):
|
|
85
214
|
"""Handler for testing API connection"""
|
|
86
215
|
|
|
@@ -164,6 +293,7 @@ def _load_jupyter_server_extension(server_app):
|
|
|
164
293
|
# Register handlers
|
|
165
294
|
handlers = [
|
|
166
295
|
(url_path_join(base_url, 'biolm', 'api', 'models'), BioLMModelsHandler),
|
|
296
|
+
(url_path_join(base_url, 'biolm', 'api', 'models', r'([^/]+)'), BioLMModelDetailsHandler),
|
|
167
297
|
(url_path_join(base_url, 'biolm', 'api', 'test-connection'), BioLMTestConnectionHandler),
|
|
168
298
|
]
|
|
169
299
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jupyterlab-biolm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "jupyterlab-biolm",
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.2.0",
|
|
10
10
|
"license": "BSD-3-Clause",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@jupyterlab/application": "^4.0.0",
|