pi-llama-cpp 0.3.0 → 0.3.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-llama-cpp",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Pi extension for llama.cpp integration. Supports both router and single modes.",
5
5
  "keywords": [
6
6
  "pi",
@@ -31,7 +31,7 @@ const selectModel = async (
31
31
  * Get available actions for a model based on its mode and status.
32
32
  *
33
33
  * @param model The selected model
34
- * @returns
34
+ * @returns The array of available actions for the given model status
35
35
  */
36
36
  const getActionsForModel = async (model: BaseModel): Promise<Array<Action>> => {
37
37
  const routerModeActions: Record<Status, Array<Action>> = {
@@ -11,6 +11,11 @@ import { DataProperty, ModelsEndpoint } from "../interfaces/endpoints/models";
11
11
  import { PropsEndpoint } from "../interfaces/endpoints/props";
12
12
  import { rpc } from "../tools/retriever";
13
13
 
14
+ /**
15
+ * Abstract base class for llama-server models.
16
+ * Provides common functionality for model identification, status checking,
17
+ * loading/unloading, and configuration conversion.
18
+ */
14
19
  export abstract class BaseModel {
15
20
  constructor(protected readonly model: DataProperty) {}
16
21
 
@@ -5,6 +5,11 @@ import { ModelsEndpoint } from "../interfaces/endpoints/models";
5
5
  import { rpc } from "../tools/retriever";
6
6
  import { BaseModel } from "./baseModel";
7
7
 
8
+ /**
9
+ * Represents a model in llama-server router mode.
10
+ * Tracks per-model status from the /models endpoint and extracts
11
+ * context size from startup arguments when the model is not loaded.
12
+ */
8
13
  export class RouterModel extends BaseModel {
9
14
  get mode(): Mode {
10
15
  return Mode.ROUTER;
@@ -25,9 +25,9 @@ const fileExists = async (filePath: string): Promise<boolean> => {
25
25
  };
26
26
 
27
27
  /**
28
- * Reads the contents of a file as JSON
29
- * @param filePath The path
30
- * @returns The content as JSON
28
+ * Reads and parses the contents of a file as JSON
29
+ * @param filePath The path to the file
30
+ * @returns The parsed content, or null if parsing fails
31
31
  */
32
32
  const readContents = async <T>(filePath: string): Promise<T | null> => {
33
33
  const raw = await readFile(filePath, "utf-8");
@@ -41,10 +41,10 @@ const readContents = async <T>(filePath: string): Promise<T | null> => {
41
41
  };
42
42
 
43
43
  /**
44
- * Reads a string value from a JSON config file
44
+ * Reads a value from a JSON config file by key
45
45
  * @param filePath Path to the JSON config file
46
46
  * @param key Key to extract from the parsed JSON
47
- * @returns The string value, or null if file/key missing or invalid
47
+ * @returns The value at the given key, or null if file/key missing or invalid
48
48
  */
49
49
  const readConfigValue = async <T>(
50
50
  filePath: string,
@@ -19,10 +19,11 @@ export const isServerReady = async (): Promise<boolean> => {
19
19
  };
20
20
 
21
21
  /**
22
- * Extracts the data of a fetch command
23
- * @param endpoint The endpoint to fetch from
24
- * @param body The body (optional)
25
- * @returns Data from the fetch command
22
+ * Makes an HTTP request to the llama-server and returns the parsed JSON response
23
+ *
24
+ * @param endpoint The endpoint path to fetch (e.g. "/health")
25
+ * @param body The optional request body for POST requests
26
+ * @returns The parsed JSON response from the server
26
27
  */
27
28
  export const rpc = async <T>(
28
29
  endpoint: string,
@@ -46,11 +47,8 @@ export const rpc = async <T>(
46
47
  },
47
48
  });
48
49
 
49
- if (!res.ok) {
50
- const text = await res.text();
51
- throw new Error(`${res.status}: ${text}`);
52
- }
53
- return res.json() as T;
50
+ const response: T = await res.json();
51
+ return response;
54
52
  };
55
53
 
56
54
  /**
@@ -62,8 +60,7 @@ export const listModels = async (): Promise<BaseModel[]> => {
62
60
  const { models, data } = await rpc<ModelsEndpoint>("/models");
63
61
 
64
62
  if (models) {
65
- const [extra] = models;
66
- return data.map((m) => new SingleModel(m, extra));
63
+ return data.map((m) => new SingleModel(m));
67
64
  }
68
65
 
69
66
  const response = data