Skip to content

Do not expose providers api #84

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

Merged
merged 6 commits into from
Jun 5, 2025
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
6 changes: 0 additions & 6 deletions src/base-completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import {
CompletionHandler,
IInlineCompletionContext
} from '@jupyterlab/completer';
import { BaseLanguageModel } from '@langchain/core/language_models/base';
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';

export interface IBaseCompleter {
/**
* The LLM completer.
*/
completer: BaseLanguageModel;

/**
* The completion prompt.
*/
Expand Down
13 changes: 10 additions & 3 deletions src/chat-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import {
IInputModel,
INewMessage
} from '@jupyter/chat';
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
import {
AIMessage,
HumanMessage,
mergeMessageRuns,
SystemMessage
} from '@langchain/core/messages';
import { UUID } from '@lumino/coreutils';

import { jupyternautLiteIcon } from './icons';
import { chatSystemPrompt } from './provider';
import { AIChatModel } from './types/ai-model';
import { IAIProviderRegistry } from './tokens';
import { jupyternautLiteIcon } from './icons';

/**
* The base64 encoded SVG string of the jupyternaut lite icon.
Expand Down Expand Up @@ -52,7 +53,7 @@ export class ChatHandler extends ChatModel {
});
}

get provider(): BaseChatModel | null {
get provider(): AIChatModel | null {
return this._providerRegistry.currentChatModel;
}

Expand Down Expand Up @@ -194,10 +195,16 @@ export class ChatHandler extends ChatModel {
}

export namespace ChatHandler {
/**
* The options used to create a chat handler.
*/
export interface IOptions extends ChatModel.IOptions {
providerRegistry: IAIProviderRegistry;
}

/**
* The chat command provider for the chat.
*/
export class ClearCommandProvider implements IChatCommandProvider {
public id: string = '@jupyterlite/ai:clear-commands';
private _slash_commands: ChatCommand[] = [
Expand Down
4 changes: 2 additions & 2 deletions src/completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
IInlineCompletionProvider
} from '@jupyterlab/completer';

import { IBaseCompleter } from './base-completer';
import { IAIProviderRegistry } from './tokens';
import { AICompleter } from './types/ai-model';

/**
* The generic completion provider to register to the completion provider manager.
Expand Down Expand Up @@ -34,7 +34,7 @@ export class CompletionProvider implements IInlineCompletionProvider {
/**
* Get the current completer.
*/
get completer(): IBaseCompleter | null {
get completer(): AICompleter | null {
return this._providerRegistry.currentCompleter;
}

Expand Down
5 changes: 0 additions & 5 deletions src/default-providers/Anthropic/completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
IInlineCompletionContext
} from '@jupyterlab/completer';
import { ChatAnthropic } from '@langchain/anthropic';
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
import { AIMessage, SystemMessage } from '@langchain/core/messages';

import { BaseCompleter, IBaseCompleter } from '../../base-completer';
Expand All @@ -14,10 +13,6 @@ export class AnthropicCompleter implements IBaseCompleter {
this._completer = new ChatAnthropic({ ...options.settings });
}

get completer(): BaseChatModel {
return this._completer;
}

/**
* Getter and setter for the initial prompt.
*/
Expand Down
5 changes: 0 additions & 5 deletions src/default-providers/ChromeAI/completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
IInlineCompletionContext
} from '@jupyterlab/completer';
import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
import { LLM } from '@langchain/core/language_models/llms';
import { HumanMessage, SystemMessage } from '@langchain/core/messages';

import { BaseCompleter, IBaseCompleter } from '../../base-completer';
Expand Down Expand Up @@ -45,10 +44,6 @@ export class ChromeCompleter implements IBaseCompleter {
this._prompt = value;
}

get completer(): LLM {
return this._completer;
}

async fetch(
request: CompletionHandler.IRequest,
context: IInlineCompletionContext
Expand Down
5 changes: 0 additions & 5 deletions src/default-providers/MistralAI/completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
CompletionHandler,
IInlineCompletionContext
} from '@jupyterlab/completer';
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
import {
BaseMessage,
HumanMessage,
Expand Down Expand Up @@ -47,10 +46,6 @@ export class CodestralCompleter implements IBaseCompleter {
);
}

get completer(): BaseChatModel {
return this._completer;
}

/**
* Getter and setter for the initial prompt.
*/
Expand Down
6 changes: 0 additions & 6 deletions src/default-providers/Ollama/completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
CompletionHandler,
IInlineCompletionContext
} from '@jupyterlab/completer';
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
import { AIMessage, SystemMessage } from '@langchain/core/messages';
import { ChatOllama } from '@langchain/ollama';

Expand All @@ -12,11 +11,6 @@ import { COMPLETION_SYSTEM_PROMPT } from '../../provider';
export class OllamaCompleter implements IBaseCompleter {
constructor(options: BaseCompleter.IOptions) {
this._completer = new ChatOllama({ ...options.settings });
console.log('Settings', options.settings);
}

get completer(): BaseChatModel {
return this._completer;
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/default-providers/OpenAI/completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
CompletionHandler,
IInlineCompletionContext
} from '@jupyterlab/completer';
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
import { AIMessage, SystemMessage } from '@langchain/core/messages';
import { ChatOpenAI } from '@langchain/openai';

Expand All @@ -14,10 +13,6 @@ export class OpenAICompleter implements IBaseCompleter {
this._completer = new ChatOpenAI({ ...options.settings });
}

get completer(): BaseChatModel {
return this._completer;
}

/**
* Getter and setter for the initial prompt.
*/
Expand Down
6 changes: 1 addition & 5 deletions src/default-providers/WebLLM/completer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
} from '@jupyterlab/completer';
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
import { ChatWebLLM } from '@langchain/community/chat_models/webllm';

import { BaseCompleter, IBaseCompleter } from '../../base-completer';
import { COMPLETION_SYSTEM_PROMPT } from '../../provider';
import { BaseChatModel } from '@langchain/core/language_models/chat_models';

/**
* Regular expression to match the '```' string at the start of a string.
Expand Down Expand Up @@ -69,10 +69,6 @@ export class WebLLMCompleter implements IBaseCompleter {
}
}

get completer(): BaseChatModel {
return this._completer;
}

/**
* Getter and setter for the initial prompt.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/default-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ const webLLMProviderPlugin: JupyterFrontEndPlugin<void> = {
completer: WebLLMCompleter,
settingsSchema: WebLLMSettings,
instructions: WebLLMInstructions,
compatibilityCheck: webLLMCompatibilityCheck
compatibilityCheck: webLLMCompatibilityCheck,
exposeChatModel: true
});

registry.providerChanged.connect(async (sender, args) => {
Expand Down
Loading