repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
node-llama-cpp
github_2023
withcatai
typescript
LlamaCompletion.generateInfillCompletion
public async generateInfillCompletion( prefixInput: Token[] | string | LlamaText, suffixInput: Token[] | string | LlamaText, options: LlamaInfillGenerationOptions = {} ) { const {response} = await this.generateInfillCompletionWithMeta(prefixInput, suffixInput, options); retu...
/** * Infill (also known as Fill-In-Middle), generates a completion for an input (`prefixInput`) that * should connect to a given continuation (`suffixInput`). * For example, for `prefixInput: "123"` and `suffixInput: "789"`, the model is expected to generate `456` * to make the final text be `12345...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaCompletion.ts#L372-L380
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaCompletion.generateInfillCompletionWithMeta
public async generateInfillCompletionWithMeta( prefixInput: Token[] | string | LlamaText, suffixInput: Token[] | string | LlamaText, { onTextChunk, onToken, signal, maxTokens, temperature, minP, topK, ...
/** * Same as `generateInfillCompletion`, but returns additional metadata about the generation. * See `generateInfillCompletion` for more information. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaCompletion.ts#L386-L565
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaCompletion._generateResponse
private async _generateResponse( tokens: Token[], { onTextChunk, onToken, signal, maxTokens, temperature, minP, topK, topP, seed, trimWhitespaceSuffix = false, repeatPenalt...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaCompletion.ts#L568-L832
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaEmbedding.calculateCosineSimilarity
public calculateCosineSimilarity(other: LlamaEmbedding | LlamaEmbeddingJSON | readonly number[]) { const otherVector = other instanceof Array ? other : other.vector; if (otherVector == null) throw new Error("Other vector is null"); else if (otherVector.length...
/** * Calculates the cosine similarity between this embedding and another embedding. * * Note that you should only compare embeddings created by the exact same model file. * @returns A value between 0 and 1 representing the similarity between the embedding vectors, * where 1 means the embedding...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaEmbedding.ts#L31-L63
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaEmbeddingContext._create
public static async _create({ _model }: { _model: LlamaModel }, { contextSize, batchSize, threads = 6, createSignal, ignoreMemorySafetyChecks }: LlamaEmbeddingContextOptions) { if (_model.fileInsights.hasEncoder && _model.fileInsights.hasDecode...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaEmbeddingContext.ts#L138-L164
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaGrammar.constructor
public constructor(llama: Llama, { grammar, stopGenerationTriggers = [], trimWhitespaceSuffix = false, rootRuleName = "root" }: LlamaGrammarOptions) { this._llama = llama; this._grammar = new this._llama._bindings.AddonGrammar(grammar, { addonExports: this._llama._bindings, ...
/** * > GBNF files are supported. * > More info here: [ * github:ggerganov/llama.cpp:grammars/README.md * ](https://github.com/ggerganov/llama.cpp/blob/f5fe98d11bdf9e7797bcfb05c0c3601ffc4b9d26/grammars/README.md) * * Prefer to create a new instance of this class by using `llama.createGramm...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaGrammar.ts#L50-L62
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaGrammar._testText
public _testText(text: string): boolean { return this._grammar.isTextCompatible(String(text)); }
/** * Test if the given text is compatible with the grammar. * @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaGrammar.ts#L84-L86
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaGrammarEvaluationState.clone
public clone(): LlamaGrammarEvaluationState { return new LlamaGrammarEvaluationState(this); }
/** Clone the grammar evaluation state */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaGrammarEvaluationState.ts#L41-L43
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaJsonSchemaGrammar.constructor
public constructor(llama: Llama, schema: Readonly<T>) { const grammar = getGbnfGrammarForGbnfJsonSchema(schema); super(llama, { grammar, stopGenerationTriggers: [LlamaText(["\n".repeat(4)])], trimWhitespaceSuffix: true }); this._schema = schema; ...
/** * Prefer to create a new instance of this class by using `llama.createGrammarForJsonSchema(...)`. * @deprecated Use `llama.createGrammarForJsonSchema(...)` instead. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaJsonSchemaGrammar.ts#L20-L30
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaRankingContext.rank
public async rank(query: Token[] | string | LlamaText, document: Token[] | string | LlamaText) { if (this.model.tokens.bos == null || this.model.tokens.eos == null || this.model.tokens.sep == null) throw new Error("Computing rankings is not supported for this model."); const resolvedInput =...
/** * Get the ranking score for a document for a query. * * A ranking score is a number between 0 and 1 representing the probability that the document is relevant to the query. * @returns a ranking score between 0 and 1 representing the probability that the document is relevant to the query. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaRankingContext.ts#L83-L97
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaRankingContext.rankAll
public async rankAll(query: Token[] | string | LlamaText, documents: Array<Token[] | string | LlamaText>): Promise<number[]> { const resolvedTokens = documents.map((document) => this._getEvaluationInput(query, document)); const maxInputTokensLength = resolvedTokens.reduce((max, tokens) => Math.max(max, ...
/** * Get the ranking scores for all the given documents for a query. * * A ranking score is a number between 0 and 1 representing the probability that the document is relevant to the query. * @returns an array of ranking scores between 0 and 1 representing the probability that the document is relev...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaRankingContext.ts#L105-L121
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaRankingContext.rankAndSort
public async rankAndSort<const T extends string>(query: Token[] | string | LlamaText, documents: T[]): Promise<Array<{ document: T, /** * A ranking score is a number between 0 and 1 representing the probability that the document is relevant to the query. */ score: number }...
/** * Get the ranking scores for all the given documents for a query and sort them by score from highest to lowest. * * A ranking score is a number between 0 and 1 representing the probability that the document is relevant to the query. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaRankingContext.ts#L128-L141
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaRankingContext._getEvaluationInput
private _getEvaluationInput(query: Token[] | string | LlamaText, document: Token[] | string | LlamaText) { if (this.model.tokens.bos == null || this.model.tokens.eos == null || this.model.tokens.sep == null) throw new Error("Computing rankings is not supported for this model."); const resol...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaRankingContext.ts#L161-L181
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaRankingContext._evaluateRankingForInput
private _evaluateRankingForInput(input: Token[]): Promise<number> { if (input.length === 0) return Promise.resolve(0); return withLock(this, "evaluate", async () => { await this._sequence.eraseContextTokenRanges([{ start: 0, end: this._sequence.ne...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaRankingContext.ts#L184-L209
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaRankingContext._create
public static async _create({ _model }: { _model: LlamaModel }, { contextSize, batchSize, threads = 6, createSignal, ignoreMemorySafetyChecks }: LlamaRankingContextOptions) { const tensorInfo = _model.fileInfo.tensorInfo; if (_model.to...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaRankingContext.ts#L212-L252
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenBias.set
public set(input: Token | Token[] | string | LlamaText, bias: "never" | number | {logit: number}) { const resolvedLogit = bias === "never" ? -Infinity : typeof bias === "number" ? probabilityToLogit(bias) : bias.logit; for (const token of tokenize...
/** * Adjust the bias of the given token(s). * * If a text is provided, the bias will be applied to each individual token in the text. * * Setting a bias to `"never"` will prevent the token from being generated, unless it is required to comply with a grammar. * * Setting the bias of t...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenBias.ts#L41-L63
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenMeter.usedInputTokens
public get usedInputTokens() { return this._inputTokens; }
/** * The number of input tokens used */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenMeter.ts#L11-L13
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenMeter.usedOutputTokens
public get usedOutputTokens() { return this._outputTokens; }
/** * The number of tokens generated by a model */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenMeter.ts#L18-L20
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenMeter.getState
public getState(): TokenMeterState { return { usedInputTokens: this.usedInputTokens, usedOutputTokens: this.usedOutputTokens }; }
/** * Get the current state of the token meter */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenMeter.ts#L25-L30
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenMeter.useTokens
public useTokens(tokens: number, type: "input" | "output") { if (tokens < 0) throw new RangeError("Tokens cannot be negative"); else if (tokens === 0) return; if (type === "input") this._inputTokens += tokens; else if (type === "output") t...
/** * Log the usage of tokens */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenMeter.ts#L35-L49
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenMeter.diff
public diff(meter: TokenMeter | TokenMeterState) { return TokenMeter.diff(this, meter); }
/** * Get the difference between the current meter and another meter */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenMeter.ts#L54-L56
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenMeter.useTokens
public static useTokens( meters: null | undefined | TokenMeter | readonly TokenMeter[] | ReadonlySet<TokenMeter>, tokens: number, type: "input" | "output" ) { if (meters == null) return; if (meters instanceof TokenMeter) meters.useTokens(tokens, type)...
/** * Log the usage of tokens on multiple meters */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenMeter.ts#L61-L75
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
TokenMeter.diff
public static diff( meter1: TokenMeter | TokenMeterState, meter2: TokenMeter | TokenMeterState ) { return { usedInputTokens: meter1.usedInputTokens - meter2.usedInputTokens, usedOutputTokens: meter1.usedOutputTokens - meter2.usedOutputTokens }; }
/** * Get the difference between two meters */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/TokenMeter.ts#L80-L88
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession.promptWithMeta
public async promptWithMeta<const Functions extends ChatSessionModelFunctions | undefined = undefined>(prompt: string, { functions, documentFunctionParams, maxParallelFunctionCalls, onTextChunk, onToken, signal, stopOnAbortSignal = false, maxTokens, ...
/** * @param prompt * @param [options] */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L441-L689
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession.preloadPrompt
public async preloadPrompt(prompt: string, options: LLamaChatPreloadPromptOptions = {}): Promise<void> { await this.completePromptWithMeta(prompt, { ...options, maxTokens: 0 }); }
/** * Preload a user prompt into the current context sequence state to make later inference of the model response begin sooner * and feel faster. * * > **Note:** Preloading a long user prompt can incur context shifts, so consider limiting the length of prompts you preload * @param prompt - the ...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L699-L704
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession.completePrompt
public async completePrompt(prompt: string, options: LLamaChatCompletePromptOptions = {}): Promise<string> { const {completion} = await this.completePromptWithMeta(prompt, options); return completion; }
/** * Preload a user prompt into the current context sequence state and generate a completion for it. * * > **Note:** Preloading a long user prompt and completing a user prompt with a high number of `maxTokens` can incur context shifts, * > so consider limiting the length of prompts you preload. ...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L716-L720
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession.createPromptCompletionEngine
public createPromptCompletionEngine(options?: LLamaChatPromptCompletionEngineOptions) { return LlamaChatSessionPromptCompletionEngine._create(this, options); }
/** * Create a smart completion engine that caches the prompt completions * and reuses them when the user prompt matches the beginning of the cached prompt or completion. * * All completions are made and cache is used only for the current chat session state. * You can create a single completion...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L729-L731
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession.completePromptWithMeta
public async completePromptWithMeta(prompt: string, { maxTokens, stopOnAbortSignal = false, functions, documentFunctionParams, onTextChunk, onToken, signal, temperature, minP, topK, topP, seed, grammar, trim...
/** * See `completePrompt` for more information. * @param prompt * @param [options] */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L738-L836
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession.resetChatHistory
public resetChatHistory() { if (this._chat == null || this.disposed) throw new DisposedError(); const chatWrapperSupportsSystemMessages = this._chat.chatWrapper.settings.supportsSystemMessages; if (chatWrapperSupportsSystemMessages == null || chatWrapperSupportsSystemMessages || thi...
/** Clear the chat history and reset it to the initial state. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L856-L867
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession._stopAllPreloadAndPromptCompletions
private _stopAllPreloadAndPromptCompletions() { for (const abortController of this._preloadAndCompleteAbortControllers) abortController.abort(); this._preloadAndCompleteAbortControllers.clear(); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L870-L875
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSession._ensureNotDisposed
private _ensureNotDisposed() { if (this.disposed) throw new DisposedError(); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/LlamaChatSession.ts#L878-L881
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSessionPromptCompletionEngine.complete
public complete(prompt: string): string { if (this._disposed) throw new DisposedError(); const completionCache = this._getCurrentCompletionCache(); const completion = completionCache.getCompletion(prompt); if (this._lastPrompt == null || !(this._lastPrompt + (completion ??...
/** * Get completion for the prompt from the cache, * and begin preloading this prompt into the context sequence and completing it. * * On completion progress, `onGeneration` (configured for this engine instance) will be called. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L89-L105
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSessionPromptCompletionEngine._getCurrentCompletionCache
private _getCurrentCompletionCache() { const completionCache = this._completionCaches.get(this._chatSession._chatHistoryStateRef); if (completionCache != null) return completionCache; const newCompletionCache = new CompletionCache(this._maxCachedCompletions); this._completi...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L108-L117
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSessionPromptCompletionEngine._restartCompletion
private _restartCompletion(completionCache: CompletionCache) { if (this._disposed) return; this._currentCompletionAbortController.abort(); this._currentCompletionAbortController = new AbortController(); const prompt = this._lastPrompt; if (prompt == null) ...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L120-L172
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaChatSessionPromptCompletionEngine._create
public static _create(chatSession: LlamaChatSession, options: LLamaChatPromptCompletionEngineOptions = {}) { return new LlamaChatSessionPromptCompletionEngine(chatSession, options); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L175-L177
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
CompletionCache._deleteInput
private _deleteInput(input: string) { let lastNodeWithMultipleChildren: InputNode = this._rootNode; let lastNodeWithMultipleChildrenDeleteChar: string = input[0]!; let node = this._rootNode; for (let i = 0; i < input.length; i++) { const [next] = node; const char...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.ts#L251-L273
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext.stateSize
public get stateSize() { this._ensureNotDisposed(); return this._ctx.getStateSize(); }
/** * The actual size of the state in the memory in bytes. * This value is provided by `llama.cpp` and doesn't include all the memory overhead of the context. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L206-L210
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext.currentThreads
public get currentThreads() { this._ensureNotDisposed(); return this._ctx.getThreads(); }
/** The number of threads currently used to evaluate tokens */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L213-L217
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext.idealThreads
public get idealThreads() { return this._idealThreads; }
/** * The number of threads that are preferred to be used to evaluate tokens. * * The actual number of threads used may be lower when other evaluations are running in parallel. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L224-L226
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext.getSequence
public getSequence(options: { contextShift?: ContextShiftOptions, /** * Token predictor to use for the sequence. * Don't share the same token predictor between multiple sequences. * * Using a token predictor doesn't affect the generation output itself - * it...
/** * Before calling this method, make sure to call `sequencesLeft` to check if there are any sequences left. * When there are no sequences left, this method will throw an error. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L249-L298
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext.printTimings
public async printTimings() { this._ensureNotDisposed(); if (!this._performanceTracking) throw new UnsupportedError("Performance tracking is not enabled"); this._ctx.printTimings(); await new Promise((accept) => setTimeout(accept, 0)); // wait for the logs to finish printin...
/** * Print the timings of token evaluation since that last print for this context. * * Requires the `performanceTracking` option to be enabled. * * > **Note:** it prints on the `LlamaLogLevel.info` level, so if you set the level of your `Llama` instance higher than that, * it won't print ...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L608-L616
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._decodeTokens
public async _decodeTokens<T>({ sequenceId, firstTokenSequenceIndex, tokens, logits, evaluationPriority = defaultEvaluationPriority, tokenMeter }: { sequenceId: number, firstTokenSequenceIndex: number, tokens: Token[], logits: (true | undefined)[], evaluationPriority?: EvaluationPriority, to...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L619-L640
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._reclaimUnusedSequenceId
public _reclaimUnusedSequenceId(sequenceId: number) { if (this._disposed) return; void withLock(this, "context", async () => { if (this._disposed) return; this._ctx.disposeSequence(sequenceId); this._unusedSequenceIds.push(sequenceId); ...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L643-L655
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._popSequenceId
private _popSequenceId(): number | null { if (this._unusedSequenceIds.length > 0) return this._unusedSequenceIds.shift()!; if (this._nextGeneratedSequenceId < this._totalSequences) { const sequenceId = this._nextGeneratedSequenceId; this._nextGeneratedSequenceId++; ...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L658-L671
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._scheduleDecode
private _scheduleDecode() { if (this._dispatchDecodeScheduled || this._batchDispatchPending) return; this._dispatchDecodeScheduled = true; const currentPendingBatchHandle = this._currentDispatchBatchHandle; const dispatch = () => { if (this._currentDispatchBatch...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L674-L705
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._dispatchErrorForQueuedDecodesAndDequeue
private _dispatchErrorForQueuedDecodesAndDequeue(queuedDecodes: ReadonlySet<InternalQueuedDecode>, err: unknown) { for (const pendingDecode of queuedDecodes) { const [, reject] = pendingDecode.response; reject(err); } for (let i = 0; i < this._queuedDecodes.length; i++) ...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L708-L722
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._ensureNotDisposed
private _ensureNotDisposed() { if (this._disposed) throw new DisposedError(); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L725-L728
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._setLora
private async _setLora({ filePath, scale }: { filePath: string, scale?: number }) { const lora = await this._model._getOrLoadLora(filePath); this._ctx.setLora(lora, scale ?? defaultLoraScale); if (!this._loraAdapters.has(lora)) { this._loraAdapters.add(lora);...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L731-L743
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._reserveThreads
private _reserveThreads() { clearTimeout(this._freeReservedThreadsTimeout); delete this._freeReservedThreadsTimeout; if (this._threadSplitterConsumer != null) return; this._threadSplitterConsumer = this._llama._threadsSplitter.createConsumer(this._idealThreads, this._minThr...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L746-L754
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._freeReservedThreads
private _freeReservedThreads() { clearTimeout(this._freeReservedThreadsTimeout); delete this._freeReservedThreadsTimeout; if (this._threadSplitterConsumer == null) return; this._threadSplitterConsumer.dispose(); delete this._threadSplitterConsumer; }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L757-L766
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._scheduleToFreeReservedThreads
private _scheduleToFreeReservedThreads() { if (this._threadSplitterConsumer == null) return; clearTimeout(this._freeReservedThreadsTimeout); this._freeReservedThreadsTimeout = setTimeout(this._freeReservedThreads, 0); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L769-L775
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContext._create
public static async _create(options: LlamaContextOptions, {_model}: { _model: LlamaModel }): Promise<LlamaContext> { const sequences = options.sequences ?? getDefaultContextSequences(); const flashAttention = _model.flashAttentionSupported ? Boolean(options.flashAttention ?? _mod...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L778-L918
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.contextSize
public get contextSize() { return this._context.contextSize; }
/** The maximum number of tokens that the sequence state can hold */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1009-L1011
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.nextTokenIndex
public get nextTokenIndex() { return this._nextTokenIndex - this._loadedTokenPredictions.length; }
/** The index where the next evaluated token will be placed in the context */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1014-L1016
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.contextTokens
public get contextTokens() { if (this._loadedTokenPredictions.length === 0) return this._contextTokens.slice(); return this._contextTokens.slice(0, -this._loadedTokenPredictions.length); }
/** The current context state tokens */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1019-L1024
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.tokenPredictor
public get tokenPredictor() { return this._tokenPredictor; }
/** * The token predictor used when creating this sequence. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1033-L1035
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.tokenPredictions
public get tokenPredictions(): { /** Number of token predictions that were actually used (tokens that were validated and then consumed) */ used: number, /** Number of token predictions that were not used (tokens that were validated and were not consumed) */ unused: number, /** ...
/** * Statistics of token predictions using the sequence's `tokenPredictor`. * * The statistics change only when token prediction is used in this sequence. * * `validated` + `refuted` = total number of evaluated predictions. * * Prefer using `validated` and `refuted` to evaluate the e...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1046-L1065
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.adaptStateToTokens
public async adaptStateToTokens(tokens: Token[], allowShift: boolean = true) { const modelSupportsShifting = !this.model.fileInsights.isRecurrent && this.model.fileInfo.metadata?.general?.architecture !== GgufArchitectureType.deepseek2; if (!modelSupportsShifting || !allowShift) { ...
/** * Erase parts of the context state to align it with the given tokens. * * If the given tokens do not align with the current context state, the context state will be erased to align with the given tokens. * * To find the first different token index between the context state and the given tok...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1098-L1144
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.clearHistory
public async clearHistory() { this._ensureNotDisposed(); await this._eraseContextTokenRanges([{start: 0, end: this._nextTokenIndex}]); }
/** * Clear the history of the sequence. * If `prependBos` was enabled, the BOS token will be prepended to the sequence again. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1150-L1154
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.eraseContextTokenRanges
public eraseContextTokenRanges(ranges: ContextTokensDeleteRange[]) { return this._eraseContextTokenRanges(ranges); }
/** * Erase context tokens in the provided ranges to free up space for new tokens to be generated. * The start of each range is inclusive, and the end of each range is exclusive. * For example, the range `{start: 0, end: 1}` will remove the token at the `0` index only. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1161-L1163
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._eraseContextTokenRanges
private async _eraseContextTokenRanges( ranges: ContextTokensDeleteRange[], { canResetTokenPredictor = true, canRemovePredictionTokens = true, skipLock = false }: { canResetTokenPredictor?: boolean, canRemovePredictionTokens?: boolean, ...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1166-L1278
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.evaluate
public async *evaluate(tokens: Token[], options: SequenceEvaluateOptions = {}): AsyncGenerator<Token, void, void | Token | Token[]> { const iterator = this.evaluateWithMetadata(tokens, {}, options); let iterateInput: void | Token | Token[] = undefined; try { while (true) { ...
/** * Evaluate the provided tokens into the context sequence, and continue generating new tokens on iterator iterations. * * This method uses the token predictor (when provided) to generate new tokens faster. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1285-L1300
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.evaluateWithMetadata
public evaluateWithMetadata<const Metadata extends SequenceEvaluateMetadataOptions>( tokens: Token[], metadata: Metadata, options: SequenceEvaluateOptions = {} ): AsyncGenerator<SequenceEvaluateOutput<Metadata>, void, void | Token | Token[]> { const { temperature = 0, ...
/** * Like {@link evaluate `.evaluate(...)`}, but with additional metadata for each generated token. * * Configure the additional metadata options to choose which metadata to include. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1307-L1368
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.evaluateWithoutGeneratingNewTokens
public async evaluateWithoutGeneratingNewTokens(tokens: Token[], options: { /** * When a lot of tokens are queued for the next batch, more than the configured `batchSize`, the tokens for each sequence will be * evaluated based on the strategy chosen for the context. * By default, the ...
/** * Evaluate the provided tokens into the context sequence without generating new tokens. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1373-L1436
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence.controlledEvaluate
public async controlledEvaluate(input: ControlledEvaluateInputItem[], options?: { /** * When a lot of tokens are queued for the next batch, more than the configured `batchSize`, the tokens for each sequence will be * evaluated based on the strategy chosen for the context. * By default...
/** * Evaluate the provided tokens into the context sequence with custom options for each token. * * This method allows for more precise control of the generation process. * * A next token will be generated for a given token only if any of the `generateNext` options for it are used. * ...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1455-L1579
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._evaluate
private async *_evaluate<const Metadata extends SequenceEvaluateMetadataOptions>(tokens: Token[], metadata: Metadata, { temperature, minP, topK, topP, seed, grammarEvaluationState, repeatPenalty, tokenBias, evaluationPriority = defaultEvaluationPri...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1582-L1717
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._speculativeEvaluate
private async *_speculativeEvaluate<const Metadata extends SequenceEvaluateMetadataOptions>(tokens: Token[], metadata: Metadata, { temperature, minP, topK, topP, seed, grammarEvaluationState, repeatPenalty, tokenBias, evaluationPriority = defaultEv...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1720-L1985
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._abortTokenPredictor
private async _abortTokenPredictor(skipClearingPredictionsFromState: boolean = false, skipLock: boolean = false) { this._tokenPredictor?.stop(); this._resetTokenPredictor = true; if (skipClearingPredictionsFromState) return; if (this._loadedTokenPredictions.length > 0) ...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L1988-L2000
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._resolveSamplerConfig
private _resolveSamplerConfig({ temperature = 0, minP = 0, topK = 40, topP = 0.95, seed, grammarEvaluationState, repeatPenalty, tokenBias }: { temperature?: number, minP?: number, topK?: number, topP?: number, seed?: number, grammarEval...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L2003-L2057
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._decodeTokens
private async _decodeTokens<T>( tokens: Token[], logits: (true | undefined)[], evaluationPriority: EvaluationPriority, tokenMeter: TokenMeter, contextShiftOptions: Required<ContextShiftOptions>, logitDataMapper: ((batchLogitIndex: BatchLogitIndex, tokenIndex: number) => T...
/** * The caller of this function has to wrap it with a lock to ensure this function doesn't run concurrently. * @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L2063-L2116
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._freeUpSpaceForTokens
private async _freeUpSpaceForTokens(contextShiftOptions: Required<ContextShiftOptions>) { this._ensureNotDisposed(); const size = Math.min( this._nextTokenIndex, Math.max( 1, contextShiftOptions.size instanceof Function ? await...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L2119-L2154
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaContextSequence._create
public static _create({ sequenceId, context, tokenMeter, contextShift: { size: contextShiftSize = Math.min(100, Math.ceil(context.contextSize / 2)), strategy: contextShiftStrategy = "eraseBeginning" } = {}, tokenPredictor }: { sequenceId: number, ...
/** * We need this to make it impossible to manually create instances of this class outside the code of this library * @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaContext.ts#L2166-L2190
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaSampler._canBeNextTokenForGrammarEvaluationState
public static _canBeNextTokenForGrammarEvaluationState( llama: Llama, grammarEvaluationState: LlamaGrammarEvaluationState, token: Token ) { return llama._bindings.AddonSampler.canBeNextTokenForGrammarEvaluationState( grammarEvaluationState._state, token ...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaSampler.ts#L35-L44
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaSampler._acceptTokenOnGrammarEvaluationState
public static _acceptTokenOnGrammarEvaluationState( llama: Llama, grammarEvaluationState: LlamaGrammarEvaluationState, token: Token ) { llama._bindings.AddonSampler.acceptGrammarEvaluationStateToken(grammarEvaluationState._state, token); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/LlamaSampler.ts#L47-L53
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
DraftSequenceTokenPredictor._canIterate
private _canIterate(): boolean { return !this._disposed && !this._stopped && (this._predictedTokens.length < this._maxTokens || this._resetPredictions); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L248-L250
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
DraftSequenceTokenPredictor._resume
private _resume() { if (this._active || !this._canIterate()) return; this._active = true; void withLock(this, "evaluate", async () => { try { const abortSignal = this._currentEvaluationAbortController.signal; if (!this._canIterate() || ab...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L253-L340
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
DraftSequenceTokenPredictor._getGrammarEvaluationStateWithTokens
private _getGrammarEvaluationStateWithTokens(tokens: Token[]) { if (this._grammarEvaluationStateOption == null) return undefined; const clone = this._grammarEvaluationStateOption.clone(); for (const token of tokens) { const canAddToken = LlamaSampler._canBeNextTokenForGr...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.ts#L343-L361
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
InputLookupTokenPredictor._findLongestPatternIndex
private _findLongestPatternIndex(findIn: Token[], lookupPattern: Token[]): [index: number, length: number] | [] { const checkIndexes: number[] = []; let bestIndex = -1; let bestIndexDiff = -1; for (let i = findIn.length - this._predictionMinLength; i >= 0; i--) { const token...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.ts#L178-L220
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.gpuLayers
public get gpuLayers(): number { return this._gpuLayers; }
/** * Number of layers offloaded to the GPU. * If GPU support is disabled, this will always be `0`. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L297-L299
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.size
public get size() { this._ensureNotDisposed(); return this._model.getModelSize(); }
/** * Total model size in memory in bytes. * * When using mmap, actual memory usage may be higher than this value due to `llama.cpp`'s performance optimizations. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L306-L310
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.detokenize
public detokenize(tokens: readonly Token[], specialTokens: boolean = false, lastTokens?: readonly Token[]): string { this._ensureNotDisposed(); if (tokens.length === 0) return ""; if (lastTokens == null || lastTokens.length === 0) return this._model.detokenize(Uint32Arr...
/** * Transform tokens into text * @param tokens - the tokens to detokenize. * @param [specialTokens] - if set to `true`, special tokens will be detokenized to their corresponding token text representation. * * Recommended for debugging purposes only. * * > **Note:** there may be addi...
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L445-L464
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.isSpecialToken
public isSpecialToken(token: Token | undefined): boolean { if (token == null) return false; if (this.getTokenAttributes(token).control) return true; const normalText = this.detokenize([token], false); if (normalText === "") return this.detokenize([t...
/** Check whether the given token is a special token (a control-type token or a token with no normal text representation) */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L477-L490
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.isEogToken
public isEogToken(token: Token | undefined): boolean { if (token == null) return false; return token === this.tokens.eos || token === this.tokens.eot || this._model.isEogToken(token); }
/** Check whether the given token is an EOG (End Of Generation) token, like EOS or EOT. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L505-L510
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.createEmbeddingContext
public async createEmbeddingContext(options: LlamaEmbeddingContextOptions = {}) { if (this._vocabOnly) throw new Error("Model is loaded in vocabOnly mode, so no context can be created"); return await LlamaEmbeddingContext._create({_model: this}, options); }
/** * @see [Using Embedding](https://node-llama-cpp.withcat.ai/guide/embedding) tutorial */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L529-L534
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.createRankingContext
public async createRankingContext(options: LlamaRankingContextOptions = {}) { if (this._vocabOnly) throw new Error("Model is loaded in vocabOnly mode, so no context can be created"); return await LlamaRankingContext._create({_model: this}, options); }
/** * @see [Reranking Documents](https://node-llama-cpp.withcat.ai/guide/embedding#reranking) tutorial */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L539-L544
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.getWarnings
public getWarnings() { this._ensureNotDisposed(); const warnings = this._fileInsights.getWarnings(this._modelPath); const modelFilePathText = `("${getReadablePath(this._modelPath)}")`; try { const beforeTextNoSpecialTokens = "some test text here"; const afterTex...
/** * Get warnings about the model file that would affect its usage. * * These warnings include all the warnings generated by `GgufInsights`, but are more comprehensive. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L551-L592
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.typeDescription
public get typeDescription(): ModelTypeDescription { this._ensureNotDisposed(); if (this._typeDescription == null) this._typeDescription = this._model.getModelDescription(); return this._typeDescription; }
/** @hidden `ModelTypeDescription` type alias is too long in the documentation */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L595-L602
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.trainContextSize
public get trainContextSize(): number { this._ensureNotDisposed(); if (this._trainContextSize == null) this._trainContextSize = this._model.getTrainContextSize(); return this._trainContextSize; }
/** The context size the model was trained on */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L605-L612
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel.embeddingVectorSize
public get embeddingVectorSize(): number { this._ensureNotDisposed(); if (this._embeddingVectorSize == null) this._embeddingVectorSize = this._model.getEmbeddingVectorSize(); return this._embeddingVectorSize; }
/** The size of an embedding vector the model can produce */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L615-L622
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelInfillTokens._ensureNotDisposed
private _ensureNotDisposed() { if (this._disposedState.disposed) throw new DisposedError(); }
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L641-L644
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel._getOrLoadLora
public async _getOrLoadLora(filePath: string) { const resolvedPath = path.resolve(process.cwd(), filePath); if (this._loraAdapters.has(resolvedPath)) return this._loraAdapters.get(resolvedPath)!; return await withLock(this._loraAdapters, "modify", async () => { if (this....
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L647-L662
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel._removeLoraUsage
public async _removeLoraUsage(loraAdapters: Set<AddonModelLora>) { return await withLock(this._loraAdapters, "modify", async () => { await Promise.all( [...loraAdapters].map(async (lora) => { lora.usages--; if (lora.usages <= 0 && this._loraAd...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L665-L678
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModel._create
public static async _create(modelOptions: LlamaModelOptions, { _llama }: { _llama: Llama }) { const {loadSignal, defaultContextFlashAttention} = modelOptions; const useMmap = _llama.supportsMmap && (modelOptions.useMmap ?? defaultUseMmap); const fileInfo = await readGguf...
/** @internal */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L681-L770
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelTokens.infill
public get infill() { this._ensureNotDisposed(); if (this._infillTokens == null) this._infillTokens = LlamaModelInfillTokens._create(this._model, this._disposedState); return this._infillTokens; }
/** * @returns infill tokens */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L798-L805
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelTokens.bos
public get bos(): Token | null { this._ensureNotDisposed(); if (this._bosToken == null) this._bosToken = this._model.tokenBos(); if (this._bosToken === -1) return null; return this._bosToken; }
/** * @returns The BOS (Beginning Of Sequence) token. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L810-L820
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelTokens.eos
public get eos(): Token | null { this._ensureNotDisposed(); if (this._eosToken == null) this._eosToken = this._model.tokenEos(); if (this._eosToken === -1) return null; return this._eosToken; }
/** * @returns The EOS (End Of Sequence) token. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L825-L835
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelTokens.eot
public get eot(): Token | null { this._ensureNotDisposed(); if (this._eotToken == null) this._eotToken = this._model.eotToken(); if (this._eotToken === -1) return null; return this._eotToken; }
/** * @returns The EOT (End Of Turn) token. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L840-L850
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelTokens.sep
public get sep(): Token | null { this._ensureNotDisposed(); if (this._sepToken == null) this._sepToken = this._model.sepToken(); if (this._sepToken === -1) return null; return this._sepToken; }
/** * @returns The SEP (Sentence Separator) token. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L855-L865
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelTokens.nl
public get nl(): Token | null { this._ensureNotDisposed(); if (this._nlToken == null) this._nlToken = this._model.tokenNl(); if (this._nlToken === -1) return null; return this._nlToken; }
/** * @returns The NL (New Line) token. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L870-L880
63a106627e1a8664ac335526c987522c94e87ce2
node-llama-cpp
github_2023
withcatai
typescript
LlamaModelTokens.bosString
public get bosString(): string | null { this._ensureNotDisposed(); const bosToken = this.bos; if (bosToken == null) return null; if (this._bosString == null) this._bosString = this._model.getTokenString(bosToken); return this._bosString; }
/** * @returns The BOS (Beginning Of Sequence) token text representation. */
https://github.com/withcatai/node-llama-cpp/blob/63a106627e1a8664ac335526c987522c94e87ce2/src/evaluator/LlamaModel/LlamaModel.ts#L885-L897
63a106627e1a8664ac335526c987522c94e87ce2