Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rendering of model IDs with a colon in their name #704

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions packages/jupyter-ai/src/components/chat-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { minifyUpdate } from './settings/minify';
import { useStackingAlert } from './mui-extras/stacking-alert';
import { RendermimeMarkdown } from './rendermime-markdown';
import { getProviderId, getModelLocalId } from '../utils';

type ChatSettingsProps = {
rmRegistry: IRenderMimeRegistry;
Expand Down Expand Up @@ -391,23 +392,6 @@ export function ChatSettings(props: ChatSettingsProps): JSX.Element {
);
}

function getProviderId(globalModelId: string) {
if (!globalModelId) {
return null;
}

return globalModelId.split(':')[0];
}

function getModelLocalId(globalModelId: string) {
if (!globalModelId) {
return null;
}

const components = globalModelId.split(':').slice(1);
return components.join(':');
}

function getProvider(
globalModelId: string,
providers: AiService.ListProvidersResponse
Expand Down
25 changes: 2 additions & 23 deletions packages/jupyter-ai/src/components/settings/use-server-info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect, useMemo, useCallback } from 'react';
import { AiService } from '../../handler';
import { getProviderId, getModelLocalId } from '../../utils';

type ServerInfoProperties = {
config: AiService.DescribeConfigResponse;
Expand Down Expand Up @@ -63,7 +64,7 @@ export function useServerInfo(): ServerInfo {
lmGid === null ? null : getProvider(lmGid, lmProviders);
const emProvider =
emGid === null ? null : getProvider(emGid, emProviders);
const lmLocalId = lmGid === null ? '' : getLocalId(lmGid);
const lmLocalId = (lmGid && getModelLocalId(lmGid)) ?? '';
setServerInfoProps({
config,
lmProviders,
Expand Down Expand Up @@ -135,25 +136,3 @@ function getProvider(
const provider = providers.providers.find(p => p.id === providerId);
return provider ?? null;
}

function getProviderId(gid: string) {
if (!gid) {
return null;
}

const components = gid.split(':');
if (components.length < 2) {
return null;
}

return components[0];
}

function getLocalId(gid: string) {
const components = gid.split(':');
if (components.length < 2) {
return '';
}

return components[1];
}
23 changes: 23 additions & 0 deletions packages/jupyter-ai/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,26 @@ export function getCellIndex(notebook: Notebook, cellId: string): number {
);
return idx === undefined ? -1 : idx;
}

/**
* Obtain the provider ID component from a model ID.
*/
export function getProviderId(globalModelId: string): string | null {
if (!globalModelId) {
return null;
}

return globalModelId.split(':')[0];
}

/**
* Obtain the model name component from a model ID.
*/
export function getModelLocalId(globalModelId: string): string | null {
if (!globalModelId) {
return null;
}

const components = globalModelId.split(':').slice(1);
return components.join(':');
}
Loading