@ruvector/ruvllm 2.7.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,48 +1,113 @@
1
1
  /**
2
2
  * RuvLLM Engine - Main orchestrator for self-learning LLM
3
3
  */
4
- import { RuvLLMConfig, GenerationConfig, QueryResponse, RoutingDecision, MemoryResult, MemoryId, RuvLLMStats, Feedback, Embedding, BatchQueryRequest, BatchQueryResponse } from './types.js';
4
+ import { RuvLLMConfig, GenerationConfig, QueryResponse, RoutingDecision, MemoryResult, MemoryId, RuvLLMStats, Feedback, Embedding, BatchQueryRequest, BatchQueryResponse, ChatMessage, GenerationResult, LoadModelOptions, LoadedModelInfo } from './types.js';
5
+ /** Returned by generate()/query() only with `allowPlaceholder` / `RUVLLM_ALLOW_MOCK=1`. */
6
+ export declare const PLACEHOLDER_TEXT = "[RuvLLM placeholder: no language model is loaded; this text is not model output]";
5
7
  /**
6
8
  * RuvLLM - Self-learning LLM orchestrator
7
9
  *
8
- * Combines SONA adaptive learning with HNSW memory,
9
- * FastGRNN routing, and SIMD-optimized inference.
10
+ * Combines SONA adaptive learning with HNSW memory, FastGRNN routing, and
11
+ * GGUF inference through the native candle backend.
12
+ *
13
+ * Text comes only from a model loaded with `loadModel()` (or the `modelPath`
14
+ * option). Without one, `generate()`, `query()`, `chat()` and
15
+ * `generateDetailed()` throw `RUVLLM_NO_LANGUAGE_MODEL`.
10
16
  *
11
17
  * @example
12
18
  * ```typescript
13
19
  * import { RuvLLM } from '@ruvector/ruvllm';
14
20
  *
15
- * const llm = new RuvLLM({ embeddingDim: 768 });
21
+ * const llm = new RuvLLM();
22
+ * llm.loadModel('./qwen2.5-0.5b-instruct-q4_k_m.gguf');
16
23
  *
17
- * // Query with automatic routing
18
- * const response = await llm.query('What is machine learning?');
19
- * console.log(response.text);
24
+ * const out = llm.chat([{ role: 'user', content: 'What is machine learning?' }], {
25
+ * maxTokens: 128,
26
+ * });
27
+ * console.log(out.text, out.finishReason, out.completionTokens);
20
28
  *
21
- * // Provide feedback for learning
29
+ * // Routed query, answered by the loaded model
30
+ * const response = llm.query('What is machine learning?');
22
31
  * llm.feedback({ requestId: response.requestId, rating: 5 });
23
32
  * ```
24
33
  */
25
34
  export declare class RuvLLM {
26
35
  private native;
36
+ private nativeVersion;
27
37
  private config;
38
+ private allowPlaceholder;
28
39
  private fallbackState;
29
40
  /**
30
41
  * Create a new RuvLLM instance
31
42
  */
32
43
  constructor(config?: RuvLLMConfig);
33
44
  /**
34
- * Query the LLM with automatic routing
45
+ * Whether the native binary can load and run a language model. False
46
+ * without a native binary, for binaries that predate `loadModel` (the 2.0.x
47
+ * `@ruvector/ruvllm-<platform>` packages), and for binaries built without
48
+ * the `candle` inference backend.
49
+ */
50
+ supportsModelLoading(): boolean;
51
+ /** Error for a binary that has `loadModel` but no inference backend. */
52
+ private noBackendError;
53
+ /**
54
+ * Load a GGUF model (or a directory holding one) for `generate()`,
55
+ * `chat()` and `query()`. Supported GGUF architectures: llama, mistral,
56
+ * qwen2, qwen3; others fail with an error naming the architecture. The
57
+ * tokenizer comes from a `tokenizer.json` beside the file, else from the
58
+ * GGUF itself. Replaces any loaded model; if loading fails, no model is
59
+ * loaded. Synchronous: blocks the event loop while the weights load.
60
+ *
61
+ * @throws `RUVLLM_NATIVE_UNAVAILABLE` without a native binary,
62
+ * `RUVLLM_NATIVE_TOO_OLD` when the binary predates model loading,
63
+ * `RUVLLM_NO_INFERENCE_BACKEND` when it was built without `candle`,
64
+ * `RUVLLM_MODEL_NOT_FOUND` / `RUVLLM_MODEL_LOAD_FAILED` from the backend.
65
+ */
66
+ loadModel(path: string, options?: LoadModelOptions): LoadedModelInfo;
67
+ /**
68
+ * Unload the language model and free its memory
69
+ */
70
+ unloadModel(): void;
71
+ /**
72
+ * Whether a language model is loaded
73
+ */
74
+ isModelLoaded(): boolean;
75
+ /**
76
+ * The loaded language model, or null
77
+ */
78
+ modelInfo(): LoadedModelInfo | null;
79
+ /**
80
+ * Route `text`, then answer it with the loaded model (as one user message
81
+ * under the model's chat template).
82
+ *
83
+ * @throws `RUVLLM_NO_LANGUAGE_MODEL` when no model is loaded, unless
84
+ * `allowPlaceholder` is set (then `text` is `PLACEHOLDER_TEXT`).
35
85
  */
36
86
  query(text: string, config?: GenerationConfig): QueryResponse;
37
87
  /**
38
- * Generate text with SIMD-optimized inference
88
+ * Continue `prompt` verbatim with the loaded model (no chat template; use
89
+ * `chat()` for instruction-tuned models). Returns the generated text.
39
90
  *
40
- * Note: the native engine has no language-model weights, so its text is
41
- * not model output; the first call emits a `RUVLLM_NO_LANGUAGE_MODEL`
42
- * warning (or throws with `strict: true`). Without the native module this
43
- * returns an informational message.
91
+ * @throws `RUVLLM_NO_LANGUAGE_MODEL` when no model is loaded, unless
92
+ * `allowPlaceholder` is set (then it returns `PLACEHOLDER_TEXT`).
44
93
  */
45
94
  generate(prompt: string, config?: GenerationConfig): string;
95
+ /**
96
+ * Like `generate()`, with token counts (from the model's tokenizer) and
97
+ * the finish reason. Always throws `RUVLLM_NO_LANGUAGE_MODEL` without a
98
+ * loaded model.
99
+ */
100
+ generateDetailed(prompt: string, config?: GenerationConfig): GenerationResult;
101
+ /**
102
+ * Run the loaded model on a conversation, formatted with the model's chat
103
+ * template (ChatML for Qwen, Llama 3 / Mistral formats for those models).
104
+ * Always throws `RUVLLM_NO_LANGUAGE_MODEL` without a loaded model.
105
+ */
106
+ chat(messages: ChatMessage[], config?: GenerationConfig): GenerationResult;
107
+ private requireModel;
108
+ private noModelError;
109
+ /** Throw `RUVLLM_NO_LANGUAGE_MODEL`, or return the labelled placeholder when opted in. */
110
+ private placeholderOrThrow;
46
111
  /**
47
112
  * Get routing decision for a query
48
113
  */
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/engine.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,eA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