perf: narrow local llama type surface

This commit is contained in:
Peter Steinberger
2026-04-18 23:38:04 +01:00
parent ecfd6cfa73
commit a0919685be
3 changed files with 60 additions and 4 deletions

View File

@@ -1,3 +1,29 @@
export type LlamaEmbedding = {
vector: Float32Array | number[];
};
export type LlamaEmbeddingContext = {
getEmbeddingFor: (text: string) => Promise<LlamaEmbedding>;
};
export type LlamaModel = {
createEmbeddingContext: () => Promise<LlamaEmbeddingContext>;
};
export type Llama = {
loadModel: (params: { modelPath: string }) => Promise<LlamaModel>;
};
export type NodeLlamaCppModule = {
LlamaLogLevel: {
error: number;
};
getLlama: (params: { logLevel: number }) => Promise<Llama>;
resolveModelFile: (modelPath: string, cacheDir?: string) => Promise<string>;
};
const NODE_LLAMA_CPP_MODULE = "node-llama-cpp";
export async function importNodeLlamaCpp() {
return import("node-llama-cpp");
return import(NODE_LLAMA_CPP_MODULE) as Promise<NodeLlamaCppModule>;
}

View File

@@ -1,8 +1,12 @@
import type { Llama, LlamaEmbeddingContext, LlamaModel } from "node-llama-cpp";
import { normalizeOptionalString } from "../../shared/string-coerce.js";
import { sanitizeAndNormalizeEmbedding } from "./embedding-vectors.js";
import type { EmbeddingProvider, EmbeddingProviderOptions } from "./embeddings.types.js";
import { importNodeLlamaCpp } from "./node-llama.js";
import {
importNodeLlamaCpp,
type Llama,
type LlamaEmbeddingContext,
type LlamaModel,
} from "./node-llama.js";
export type {
EmbeddingProvider,

View File

@@ -1,3 +1,29 @@
export type LlamaEmbedding = {
vector: Float32Array | number[];
};
export type LlamaEmbeddingContext = {
getEmbeddingFor: (text: string) => Promise<LlamaEmbedding>;
};
export type LlamaModel = {
createEmbeddingContext: () => Promise<LlamaEmbeddingContext>;
};
export type Llama = {
loadModel: (params: { modelPath: string }) => Promise<LlamaModel>;
};
export type NodeLlamaCppModule = {
LlamaLogLevel: {
error: number;
};
getLlama: (params: { logLevel: number }) => Promise<Llama>;
resolveModelFile: (modelPath: string, cacheDir?: string) => Promise<string>;
};
const NODE_LLAMA_CPP_MODULE = "node-llama-cpp";
export async function importNodeLlamaCpp() {
return import("node-llama-cpp");
return import(NODE_LLAMA_CPP_MODULE) as Promise<NodeLlamaCppModule>;
}