Skip to content

Commit e7f4196

Browse files
authored
Added jupyter-ai-litellm pkg, removed related code (#5)
* Added jupyter-ai-litellm pkg, removed related code * lint * Removed api namespace * Updated endpoints * lint
1 parent de5b0c1 commit e7f4196

File tree

9 files changed

+51
-99
lines changed

9 files changed

+51
-99
lines changed

CLAUDE.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,40 @@ This is **jupyter_ai_jupyternaut**, a JupyterLab extension that provides the def
1313
## Development Commands
1414

1515
### Setup
16+
1617
```bash
1718
micromamba install uv jupyterlab nodejs=22
1819
jlpm
1920
jlpm dev:install
2021
```
2122

2223
### Build Commands
24+
2325
- `jlpm build` - Build TypeScript sources with source maps
2426
- `jlpm build:prod` - Production build (clean + lib + labextension)
2527
- `jlpm build:lib` - Build TypeScript library only
2628
- `jlpm build:labextension` - Build JupyterLab extension
2729

2830
### Development
31+
2932
- `jlpm watch` - Watch source files and auto-rebuild
3033
- `jlpm dev:install` - Full development installation
3134
- `jlpm dev:uninstall` - Remove development installation
3235

3336
### Testing
37+
3438
- **Frontend**: `jlpm test` (Jest)
3539
- **Backend**: `pytest -vv -r ap --cov jupyter_ai_jupyternaut`
3640
- **UI Tests**: See `ui-tests/README.md` (Playwright/Galata)
3741

3842
### Code Quality
43+
3944
- `jlpm lint` - Run all linters (stylelint + prettier + eslint)
4045
- `jlpm lint:check` - Check without fixing
4146
- Individual tools: `jlpm eslint`, `jlpm prettier`, `jlpm stylelint`
4247

4348
### Clean Commands
49+
4450
- `jlpm clean` - Clean lib directory
4551
- `jlpm clean:all` - Clean everything including labextension
4652

@@ -71,6 +77,7 @@ jlpm dev:install
7177
- **Frontend**: `@jupyter/chat`, `@mui/material`, `@emotion/react`, JupyterLab 4.x
7278

7379
### File Structure
80+
7481
- `jupyter_ai_jupyternaut/` - Python package (server extension)
7582
- `jupyternaut/` - Core persona implementation
7683
- `config/` - Configuration management
@@ -89,7 +96,8 @@ jlpm dev:install
8996
- Entry point registration allows automatic persona discovery by Jupyter AI
9097

9198
### Code Style
99+
92100
- TypeScript: ESLint with Prettier, single quotes, no trailing commas
93101
- Python: Standard formatting (details in pyproject.toml)
94102
- Interface naming: Must start with `I` and use PascalCase
95-
- CSS: Stylelint with standard config
103+
- CSS: Stylelint with standard config

jupyter_ai_jupyternaut/extension_app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .config import ConfigManager, ConfigRestAPI
1212
from .handlers import RouteHandler
1313
from .jupyternaut import JupyternautPersona
14-
from .models import ChatModelsRestAPI, ModelParametersRestAPI
14+
from .models import ModelParametersRestAPI
1515
from .secrets import EnvSecretsManager, SecretsRestAPI
1616

1717
if TYPE_CHECKING:
@@ -38,7 +38,6 @@ class JupyternautExtension(ExtensionApp):
3838
handlers = [
3939
(r"api/jupyternaut/get-example/?", RouteHandler),
4040
(r"api/jupyternaut/config/?", ConfigRestAPI),
41-
(r"api/jupyternaut/models/chat/?", ChatModelsRestAPI),
4241
(r"api/jupyternaut/model-parameters/?", ModelParametersRestAPI),
4342
(r"api/jupyternaut/secrets/?", SecretsRestAPI),
4443
(
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
from .model_list import CHAT_MODELS, EMBEDDING_MODELS
2-
from .chat_models_rest_api import ChatModelsRestAPI
31
from .parameters_rest_api import ModelParametersRestAPI

jupyter_ai_jupyternaut/models/chat_models_rest_api.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

jupyter_ai_jupyternaut/models/model_list.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies = [
3838
# NOTE: Make sure to update the corresponding dependency in
3939
# `packages/jupyter-ai/package.json` to match the version range below
4040
"jupyterlab-chat>=0.17.0,<0.18.0",
41-
"litellm>=1.73,<2",
41+
"jupyter_ai_litellm>=0.0.1",
4242
"jinja2>=3.0,<4",
4343
"python_dotenv>=1,<2",
4444
"jupyter_ai_persona_manager>=0.0.1",

src/components/message-footer/stop-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function StopButton(props: MessageFooterSectionProps): JSX.Element {
4343

4444
const onClick = () => {
4545
// Post request to the stop streaming handler.
46-
requestAPI('chats/stop_streaming', {
46+
requestAPI('api/jupyternaut/chats/stop_streaming', {
4747
method: 'POST',
4848
body: JSON.stringify({
4949
message_id: message.id

src/handler.ts

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { URLExt } from '@jupyterlab/coreutils';
22

33
import { ServerConnection } from '@jupyterlab/services';
44

5-
const API_NAMESPACE = 'api/jupyternaut';
6-
75
/**
86
* Call the API extension
97
*
10-
* @param endPoint API REST end point for the extension
8+
* @param endPoint Full API REST end point path for the extension
119
* @param init Initial values for the request
1210
* @returns The response body interpreted as JSON
1311
*/
@@ -17,7 +15,7 @@ export async function requestAPI<T>(
1715
): Promise<T> {
1816
// Make request to Jupyter API
1917
const settings = ServerConnection.makeSettings();
20-
const requestUrl = URLExt.join(settings.baseUrl, API_NAMESPACE, endPoint);
18+
const requestUrl = URLExt.join(settings.baseUrl, endPoint);
2119

2220
let response: Response;
2321
try {
@@ -76,7 +74,7 @@ export namespace AiService {
7674
};
7775

7876
export async function getConfig(): Promise<DescribeConfigResponse> {
79-
return requestAPI<DescribeConfigResponse>('config');
77+
return requestAPI<DescribeConfigResponse>('api/jupyternaut/config');
8078
}
8179

8280
export type EnvAuthStrategy = {
@@ -120,17 +118,19 @@ export namespace AiService {
120118
};
121119

122120
export async function listLmProviders(): Promise<ListProvidersResponse> {
123-
return requestAPI<ListProvidersResponse>('providers');
121+
return requestAPI<ListProvidersResponse>('api/jupyternaut/providers');
124122
}
125123

126124
export async function listEmProviders(): Promise<ListProvidersResponse> {
127-
return requestAPI<ListProvidersResponse>('providers/embeddings');
125+
return requestAPI<ListProvidersResponse>(
126+
'api/jupyternaut/providers/embeddings'
127+
);
128128
}
129129

130130
export async function updateConfig(
131131
config: UpdateConfigRequest
132132
): Promise<void> {
133-
return requestAPI<void>('config', {
133+
return requestAPI<void>('api/jupyternaut/config', {
134134
method: 'POST',
135135
body: JSON.stringify(config)
136136
});
@@ -142,7 +142,7 @@ export namespace AiService {
142142
};
143143

144144
export async function listSecrets(): Promise<SecretsList> {
145-
return requestAPI<SecretsList>('secrets/', {
145+
return requestAPI<SecretsList>('api/jupyternaut/secrets/', {
146146
method: 'GET'
147147
});
148148
}
@@ -154,7 +154,7 @@ export namespace AiService {
154154
export async function updateSecrets(
155155
updatedSecrets: Record<string, string | null>
156156
): Promise<void> {
157-
return requestAPI<void>('secrets/', {
157+
return requestAPI<void>('api/jupyternaut/secrets/', {
158158
method: 'PUT',
159159
body: JSON.stringify({
160160
updated_secrets: updatedSecrets
@@ -167,14 +167,19 @@ export namespace AiService {
167167
}
168168

169169
export async function listChatModels(): Promise<string[]> {
170-
const response = await requestAPI<ListChatModelsResponse>('models/chat/', {
171-
method: 'GET'
172-
});
170+
const response = await requestAPI<ListChatModelsResponse>(
171+
'api/ai/models/chat/',
172+
{
173+
method: 'GET'
174+
}
175+
);
173176
return response.chat_models;
174177
}
175178

176179
export async function getChatModel(): Promise<string | null> {
177-
const response = await requestAPI<DescribeConfigResponse>('config/');
180+
const response = await requestAPI<DescribeConfigResponse>(
181+
'api/jupyternaut/config/'
182+
);
178183
return response.model_provider_id;
179184
}
180185

@@ -185,7 +190,9 @@ export namespace AiService {
185190
}
186191

187192
export async function getCompletionModel(): Promise<string | null> {
188-
const response = await requestAPI<DescribeConfigResponse>('config/');
193+
const response = await requestAPI<DescribeConfigResponse>(
194+
'api/jupyternaut/config/'
195+
);
189196
return response.completions_model_provider_id;
190197
}
191198

@@ -228,22 +235,27 @@ export namespace AiService {
228235
const endpoint = `model-parameters${
229236
params.toString() ? `?${params.toString()}` : ''
230237
}`;
231-
return await requestAPI<GetModelParametersResponse>(endpoint);
238+
return await requestAPI<GetModelParametersResponse>(
239+
`api/jupyternaut/${endpoint}`
240+
);
232241
}
233242

234243
export async function saveModelParameters(
235244
modelId: string,
236245
parameters: Record<string, any>
237246
): Promise<UpdateModelParametersResponse> {
238-
return await requestAPI<UpdateModelParametersResponse>('model-parameters', {
239-
method: 'PUT',
240-
headers: {
241-
'Content-Type': 'application/json'
242-
},
243-
body: JSON.stringify({
244-
model_id: modelId,
245-
parameters: parameters
246-
})
247-
});
247+
return await requestAPI<UpdateModelParametersResponse>(
248+
'api/jupyternaut/model-parameters',
249+
{
250+
method: 'PUT',
251+
headers: {
252+
'Content-Type': 'application/json'
253+
},
254+
body: JSON.stringify({
255+
model_id: modelId,
256+
parameters: parameters
257+
})
258+
}
259+
);
248260
}
249261
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
4242
activate: (app: JupyterFrontEnd) => {
4343
console.log('JupyterLab extension @jupyter-ai/jupyternaut is activated!');
4444

45-
requestAPI<any>('get-example')
45+
requestAPI<any>('api/jupyternaut/get-example')
4646
.then(data => {
4747
console.log(data);
4848
})

0 commit comments

Comments
 (0)