-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd6de45
commit 81ed00a
Showing
21 changed files
with
5,776 additions
and
4 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
File renamed without changes.
File renamed without changes.
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,65 @@ | ||
import { AppConfig } from "./config"; | ||
import { InitProgressCallback, ChatInterface, ChatOptions, GenerateProgressCallback, LogitProcessor } from "./types"; | ||
/** | ||
* This is the main interface to the chat module. | ||
*/ | ||
export declare class ChatModule implements ChatInterface { | ||
private logger; | ||
private logitProcessorRegistry?; | ||
private logitProcessor?; | ||
private pipeline?; | ||
private initProgressCallback?; | ||
private interruptSignal; | ||
private deviceLostIsError; | ||
constructor(logitProcessorRegistry?: Map<string, LogitProcessor>); | ||
setInitProgressCallback(initProgressCallback: InitProgressCallback): void; | ||
reload(localId: string, chatOpts?: ChatOptions, appConfig?: AppConfig): Promise<void>; | ||
generate(input: string, progressCallback?: GenerateProgressCallback, streamInterval?: number): Promise<string>; | ||
interruptGenerate(): Promise<void>; | ||
runtimeStatsText(): Promise<string>; | ||
resetChat(keepStats?: boolean): Promise<void>; | ||
unload(): Promise<void>; | ||
getMaxStorageBufferBindingSize(): Promise<number>; | ||
getGPUVendor(): Promise<string>; | ||
forwardTokensAndSample(inputIds: Array<number>, curPos: number, isPrefill: boolean): Promise<number>; | ||
/** | ||
* @returns Whether the generation stopped. | ||
*/ | ||
stopped(): boolean; | ||
/** | ||
* Get the current generated response. | ||
* | ||
* @returns The current output message. | ||
*/ | ||
getMessage(): string; | ||
/** | ||
* Run a prefill step with a given input. | ||
* @param input The input prompt. | ||
*/ | ||
prefill(input: string): Promise<void>; | ||
/** | ||
* Run a decode step to decode the next token. | ||
*/ | ||
decode(): Promise<void>; | ||
private getPipeline; | ||
private asyncLoadTokenizer; | ||
} | ||
/** | ||
* This is the interface to the chat module that connects to the REST API. | ||
*/ | ||
export declare class ChatRestModule implements ChatInterface { | ||
private logger; | ||
private initProgressCallback?; | ||
setInitProgressCallback(initProgressCallback: InitProgressCallback): void; | ||
reload(localId: string, chatOpts?: ChatOptions, appConfig?: AppConfig): Promise<void>; | ||
getMaxStorageBufferBindingSize(): Promise<number>; | ||
getGPUVendor(): Promise<string>; | ||
unload(): Promise<void>; | ||
interruptGenerate(): Promise<void>; | ||
forwardTokensAndSample(inputIds: Array<number>, curPos: number, isPrefill: boolean): Promise<number>; | ||
generate(input: string, progressCallback?: GenerateProgressCallback, streamInterval?: number): Promise<string>; | ||
runtimeStatsText(): Promise<string>; | ||
resetChat(keepStats?: boolean): Promise<void>; | ||
} | ||
export declare function hasModelInCache(localId: string, appConfig?: AppConfig): Promise<boolean>; | ||
//# sourceMappingURL=chat_module.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Conversation template config | ||
*/ | ||
export interface ConvTemplateConfig { | ||
system: string; | ||
roles: Array<string>; | ||
seps: Array<string>; | ||
separator_style: string; | ||
offset: number; | ||
stop_str: string; | ||
add_bos: boolean; | ||
stop_tokens: Array<number>; | ||
} | ||
/** | ||
* Config of one chat model | ||
*/ | ||
export interface ChatConfig { | ||
tokenizer_files: Array<string>; | ||
conv_config?: Partial<ConvTemplateConfig>; | ||
conv_template: string; | ||
mean_gen_len: number; | ||
shift_fill_factor: number; | ||
repetition_penalty: number; | ||
top_p: number; | ||
temperature: number; | ||
} | ||
/** | ||
* Information for a model. | ||
* @param model_url: the huggingface link to download the model weights. | ||
* @param local_id: what we call the model. | ||
* @param model_lib_url: link to the model library (wasm file) the model uses. | ||
* @param vram_required_MB: amount of vram in MB required to run the model (can use | ||
* `utils/vram_requirements` to calculate). | ||
* @param low_resource_required: whether the model can run on limited devices (e.g. Android phone). | ||
* @param required_features: feature needed to run this model (e.g. shader-f16). | ||
*/ | ||
export interface ModelRecord { | ||
model_url: string; | ||
local_id: string; | ||
model_lib_url: string; | ||
vram_required_MB?: number; | ||
low_resource_required?: boolean; | ||
required_features?: Array<string>; | ||
} | ||
/** | ||
* Extra configuration that can be | ||
* passed to the load. | ||
* | ||
* @param model_list: models to be used. | ||
*/ | ||
export interface AppConfig { | ||
model_list: Array<ModelRecord>; | ||
} | ||
/** | ||
* Default models and model library mapping to be used if unspecified. | ||
*/ | ||
export declare const prebuiltAppConfig: AppConfig; | ||
//# sourceMappingURL=config.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ConvTemplateConfig } from "./config"; | ||
/** | ||
* Helper to keep track of history conversations. | ||
*/ | ||
export declare class Conversation { | ||
messages: Array<[string, string | undefined]>; | ||
config: ConvTemplateConfig; | ||
constructor(config: ConvTemplateConfig); | ||
private getPromptArrayInternal; | ||
/** | ||
* Get prompt arrays with the first one as system. | ||
* | ||
* @returns The prompt array. | ||
*/ | ||
getPromptArray(): Array<string>; | ||
/** | ||
* Get the last round of prompt has not been fed as input. | ||
* | ||
* @note This function needs to be used with the assumption that | ||
* the caller call appendMessage then appendReplyHeader. | ||
* | ||
* @returns The prompt array. | ||
*/ | ||
getPrompArrayLastRound(): string[]; | ||
reset(): void; | ||
getStopStr(): string; | ||
getStopTokens(): number[]; | ||
appendMessage(role: string, message: string): void; | ||
appendReplyHeader(role: string): void; | ||
finishReply(message: string): void; | ||
} | ||
export declare function getConversation(conv_template: string, conv_config?: Partial<ConvTemplateConfig>): Conversation; | ||
//# sourceMappingURL=conversation.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { ModelRecord, AppConfig } from "./config"; | ||
export { InitProgressCallback, InitProgressReport, ChatOptions, ChatInterface, LogitProcessor, } from "./types"; | ||
export { ChatModule, ChatRestModule, hasModelInCache } from "./chat_module"; | ||
export { ChatWorkerHandler, ChatWorkerClient, WorkerMessage, CustomRequestParams } from "./web_worker"; | ||
//# sourceMappingURL=index.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.