Skip to content

Commit 144cc9b

Browse files
authored
fix rendering of model IDs with a colon in their name (#704)
1 parent 35202d0 commit 144cc9b

File tree

3 files changed

+26
-40
lines changed

3 files changed

+26
-40
lines changed

packages/jupyter-ai/src/components/chat-settings.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
2323
import { minifyUpdate } from './settings/minify';
2424
import { useStackingAlert } from './mui-extras/stacking-alert';
2525
import { RendermimeMarkdown } from './rendermime-markdown';
26+
import { getProviderId, getModelLocalId } from '../utils';
2627

2728
type ChatSettingsProps = {
2829
rmRegistry: IRenderMimeRegistry;
@@ -391,23 +392,6 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
391392
);
392393
}
393394

394-
function getProviderId(globalModelId: string) {
395-
if (!globalModelId) {
396-
return null;
397-
}
398-
399-
return globalModelId.split(':')[0];
400-
}
401-
402-
function getModelLocalId(globalModelId: string) {
403-
if (!globalModelId) {
404-
return null;
405-
}
406-
407-
const components = globalModelId.split(':').slice(1);
408-
return components.join(':');
409-
}
410-
411395
function getProvider(
412396
globalModelId: string,
413397
providers: AiService.ListProvidersResponse

packages/jupyter-ai/src/components/settings/use-server-info.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState, useEffect, useMemo, useCallback } from 'react';
22
import { AiService } from '../../handler';
3+
import { getProviderId, getModelLocalId } from '../../utils';
34

45
type ServerInfoProperties = {
56
config: AiService.DescribeConfigResponse;
@@ -63,7 +64,7 @@ export function useServerInfo(): ServerInfo {
6364
lmGid === null ? null : getProvider(lmGid, lmProviders);
6465
const emProvider =
6566
emGid === null ? null : getProvider(emGid, emProviders);
66-
const lmLocalId = lmGid === null ? '' : getLocalId(lmGid);
67+
const lmLocalId = (lmGid && getModelLocalId(lmGid)) ?? '';
6768
setServerInfoProps({
6869
config,
6970
lmProviders,
@@ -135,25 +136,3 @@ function getProvider(
135136
const provider = providers.providers.find(p => p.id === providerId);
136137
return provider ?? null;
137138
}
138-
139-
function getProviderId(gid: string) {
140-
if (!gid) {
141-
return null;
142-
}
143-
144-
const components = gid.split(':');
145-
if (components.length < 2) {
146-
return null;
147-
}
148-
149-
return components[0];
150-
}
151-
152-
function getLocalId(gid: string) {
153-
const components = gid.split(':');
154-
if (components.length < 2) {
155-
return '';
156-
}
157-
158-
return components[1];
159-
}

packages/jupyter-ai/src/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,26 @@ export function getCellIndex(notebook: Notebook, cellId: string): number {
4848
);
4949
return idx === undefined ? -1 : idx;
5050
}
51+
52+
/**
53+
* Obtain the provider ID component from a model ID.
54+
*/
55+
export function getProviderId(globalModelId: string): string | null {
56+
if (!globalModelId) {
57+
return null;
58+
}
59+
60+
return globalModelId.split(':')[0];
61+
}
62+
63+
/**
64+
* Obtain the model name component from a model ID.
65+
*/
66+
export function getModelLocalId(globalModelId: string): string | null {
67+
if (!globalModelId) {
68+
return null;
69+
}
70+
71+
const components = globalModelId.split(':').slice(1);
72+
return components.join(':');
73+
}

0 commit comments

Comments
 (0)