-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides only one completion provider
- Loading branch information
Showing
12 changed files
with
208 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
CompletionHandler, | ||
IInlineCompletionContext, | ||
IInlineCompletionProvider | ||
} from '@jupyterlab/completer'; | ||
import { LLM } from '@langchain/core/language_models/llms'; | ||
|
||
import { getCompleter, IBaseCompleter } from './llm-models'; | ||
|
||
/** | ||
* The generic completion provider to register to the completion provider manager. | ||
*/ | ||
export class CompletionProvider implements IInlineCompletionProvider { | ||
readonly identifier = '@jupyterlite/ai'; | ||
|
||
constructor(options: CompletionProvider.IOptions) { | ||
this.name = options.name; | ||
} | ||
|
||
/** | ||
* Getter and setter of the name. | ||
* The setter will create the appropriate completer, accordingly to the name. | ||
*/ | ||
get name(): string { | ||
return this._name; | ||
} | ||
set name(name: string) { | ||
this._name = name; | ||
this._completer = getCompleter(name); | ||
} | ||
|
||
/** | ||
* get the current completer. | ||
*/ | ||
get completer(): IBaseCompleter | null { | ||
return this._completer; | ||
} | ||
|
||
/** | ||
* Get the LLM completer. | ||
*/ | ||
get llmCompleter(): LLM | null { | ||
return this._completer?.client || null; | ||
} | ||
|
||
async fetch( | ||
request: CompletionHandler.IRequest, | ||
context: IInlineCompletionContext | ||
) { | ||
return this._completer?.fetch(request, context); | ||
} | ||
|
||
private _name: string = 'None'; | ||
private _completer: IBaseCompleter | null = null; | ||
} | ||
|
||
export namespace CompletionProvider { | ||
export interface IOptions { | ||
name: string; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
CompletionHandler, | ||
IInlineCompletionContext | ||
} from '@jupyterlab/completer'; | ||
import { LLM } from '@langchain/core/language_models/llms'; | ||
|
||
export interface IBaseCompleter { | ||
/** | ||
* The LLM completer. | ||
*/ | ||
client: LLM; | ||
|
||
/** | ||
* The fetch request for the LLM completer. | ||
*/ | ||
fetch( | ||
request: CompletionHandler.IRequest, | ||
context: IInlineCompletionContext | ||
): Promise<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './base-completer'; | ||
export * from './codestral-completer'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { BaseChatModel } from '@langchain/core/language_models/chat_models'; | ||
import { ChatMistralAI } from '@langchain/mistralai'; | ||
import { IBaseCompleter } from './base-completer'; | ||
import { CodestralCompleter } from './codestral-completer'; | ||
|
||
/** | ||
* Get an LLM completer from the name. | ||
*/ | ||
export function getCompleter(name: string): IBaseCompleter | null { | ||
if (name === 'MistralAI') { | ||
return new CodestralCompleter(); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Get an LLM chat model from the name. | ||
*/ | ||
export function getChatModel(name: string): BaseChatModel | null { | ||
if (name === 'MistralAI') { | ||
return new ChatMistralAI({ apiKey: 'TMP' }); | ||
} | ||
return null; | ||
} |
Oops, something went wrong.