Skip to content

Commit

Permalink
package back
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGOrtega committed Apr 12, 2024
1 parent cd6de45 commit 81ed00a
Show file tree
Hide file tree
Showing 21 changed files with 5,776 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/008Q/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"watch": "webpack --watch"
},
"dependencies": {
"@mlc-ai/web-llm": "file:../../3Party/web-llm",
"@mlc-ai/web-llm": "file:../web-llm",
"audiobuffer-to-wav": "^1.0.0",
"onnxruntime-web": "^1.16.3",
"whisper-webgpu": "^0.8.0"
Expand Down
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions packages/web-llm/lib/chat_module.d.ts
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
1 change: 1 addition & 0 deletions packages/web-llm/lib/chat_module.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions packages/web-llm/lib/config.d.ts
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
1 change: 1 addition & 0 deletions packages/web-llm/lib/config.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions packages/web-llm/lib/conversation.d.ts
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
1 change: 1 addition & 0 deletions packages/web-llm/lib/conversation.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/web-llm/lib/index.d.ts
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
1 change: 1 addition & 0 deletions packages/web-llm/lib/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 81ed00a

Please sign in to comment.