Skip to content

Commit 5c95321

Browse files
committed
chore: add internal debug method
1 parent 8d85100 commit 5c95321

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

llama/addon/AddonContext.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,19 @@ Napi::Value AddonContext::GetSequenceKvCacheMinPosition(const Napi::CallbackInfo
638638

639639
return Napi::Number::New(info.Env(), minPosition);
640640
}
641+
Napi::Value AddonContext::GetSequenceKvCacheMaxPosition(const Napi::CallbackInfo& info) {
642+
if (disposed) {
643+
Napi::Error::New(info.Env(), "Context is disposed").ThrowAsJavaScriptException();
644+
return info.Env().Undefined();
645+
}
646+
647+
int32_t sequenceId = info[0].As<Napi::Number>().Int32Value();
648+
649+
650+
const auto maxPosition = llama_kv_self_seq_pos_max(ctx, sequenceId);
651+
652+
return Napi::Number::New(info.Env(), maxPosition);
653+
}
641654
Napi::Value AddonContext::DecodeBatch(const Napi::CallbackInfo& info) {
642655
AddonContextDecodeBatchWorker* worker = new AddonContextDecodeBatchWorker(info.Env(), this);
643656
worker->Queue();
@@ -945,6 +958,7 @@ void AddonContext::init(Napi::Object exports) {
945958
InstanceMethod("removeTokenCellsFromSequence", &AddonContext::RemoveTokenCellsFromSequence),
946959
InstanceMethod("shiftSequenceTokenCells", &AddonContext::ShiftSequenceTokenCells),
947960
InstanceMethod("getSequenceKvCacheMinPosition", &AddonContext::GetSequenceKvCacheMinPosition),
961+
InstanceMethod("getSequenceKvCacheMaxPosition", &AddonContext::GetSequenceKvCacheMaxPosition),
948962
InstanceMethod("decodeBatch", &AddonContext::DecodeBatch),
949963
InstanceMethod("sampleToken", &AddonContext::SampleToken),
950964
InstanceMethod("getEmbedding", &AddonContext::GetEmbedding),

llama/addon/AddonContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class AddonContext : public Napi::ObjectWrap<AddonContext> {
3737
Napi::Value RemoveTokenCellsFromSequence(const Napi::CallbackInfo& info);
3838
Napi::Value ShiftSequenceTokenCells(const Napi::CallbackInfo& info);
3939
Napi::Value GetSequenceKvCacheMinPosition(const Napi::CallbackInfo& info);
40+
Napi::Value GetSequenceKvCacheMaxPosition(const Napi::CallbackInfo& info);
4041
Napi::Value DecodeBatch(const Napi::CallbackInfo& info);
4142
Napi::Value SampleToken(const Napi::CallbackInfo& info);
4243

src/bindings/AddonTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export type AddonContext = {
146146
shiftSequenceTokenCells(sequenceId: number, startPos: number, endPos: number, shiftDelta: number): void,
147147

148148
getSequenceKvCacheMinPosition(sequenceId: number): number,
149+
getSequenceKvCacheMaxPosition(sequenceId: number): number,
149150
getEmbedding(inputTokensLength: number, maxVectorSize?: number): Float64Array,
150151
getStateSize(): number,
151152
getThreads(): number,

src/bindings/getLlama.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ export async function getLlama(options?: LlamaOptions | "lastBuild", lastBuildOp
365365
return getLlamaForOptions(options ?? {});
366366
}
367367

368+
// internal
368369
export async function getLlamaForOptions({
369370
gpu = defaultLlamaCppGpuSupport,
370371
logLevel = defaultLlamaCppLogLevel,

0 commit comments

Comments
 (0)