new_pull
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { once } from "node:events";
|
||||
import { createServer, type RequestListener, type Server, type ServerResponse } from "node:http";
|
||||
import type { AddressInfo } from "node:net";
|
||||
import type { AuthContext, AuthPrompt } from "@earendil-works/pi-ai";
|
||||
import type { AuthContext, AuthPrompt, ModelsStoreEntry } from "@earendil-works/pi-ai";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { createEventBus } from "../src/core/event-bus.ts";
|
||||
import { createExtensionRuntime, loadExtensionFromFactory } from "../src/core/extensions/loader.ts";
|
||||
@@ -67,7 +67,7 @@ describe("llama.cpp extension", () => {
|
||||
id: "loaded",
|
||||
status: { value: "loaded", args: ["llama-server", "--n-gpu-layers", "999"] },
|
||||
architecture: { input_modalities: ["text", "image"] },
|
||||
meta: { n_ctx: 16384, n_ctx_train: 131072 },
|
||||
meta: { n_ctx: 65536, n_ctx_train: 131072 },
|
||||
},
|
||||
{ id: "unloaded", status: { value: "unloaded" } },
|
||||
{ id: "loading", status: { value: "loading" } },
|
||||
@@ -79,13 +79,57 @@ describe("llama.cpp extension", () => {
|
||||
expect.objectContaining({
|
||||
id: "loaded",
|
||||
baseUrl: "http://localhost:8080/v1",
|
||||
contextWindow: 16384,
|
||||
maxTokens: 16384,
|
||||
contextWindow: 65536,
|
||||
maxTokens: 65536,
|
||||
input: ["text", "image"],
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("persists and restores loaded models for cache-only startup refreshes", async () => {
|
||||
let cachedEntry: ModelsStoreEntry | undefined;
|
||||
const store = {
|
||||
read: async () => cachedEntry,
|
||||
write: async (entry: ModelsStoreEntry) => {
|
||||
cachedEntry = structuredClone(entry);
|
||||
},
|
||||
delete: async () => {
|
||||
cachedEntry = undefined;
|
||||
},
|
||||
};
|
||||
const { url } = await listen((request, response) => {
|
||||
if (request.url === "/models") {
|
||||
json(response, {
|
||||
data: [
|
||||
{ id: "loaded", status: { value: "loaded" }, meta: { n_ctx: 32768 } },
|
||||
{ id: "unloaded", status: { value: "unloaded" } },
|
||||
],
|
||||
});
|
||||
return;
|
||||
}
|
||||
response.writeHead(404).end();
|
||||
});
|
||||
|
||||
const first = createLlamaProvider();
|
||||
await first.provider.refreshModels?.({
|
||||
credential: { type: "api_key", key: "local", env: { LLAMA_BASE_URL: url } },
|
||||
store,
|
||||
allowNetwork: true,
|
||||
});
|
||||
expect(first.provider.getModels().map((model) => model.id)).toEqual(["loaded"]);
|
||||
expect(cachedEntry?.models.map((model) => model.id)).toEqual(["loaded"]);
|
||||
|
||||
const second = createLlamaProvider();
|
||||
await second.provider.refreshModels?.({
|
||||
credential: { type: "api_key", key: "local", env: { LLAMA_BASE_URL: url } },
|
||||
store,
|
||||
allowNetwork: false,
|
||||
});
|
||||
expect(second.provider.getModels()).toEqual([
|
||||
expect.objectContaining({ id: "loaded", baseUrl: `${url}/v1`, contextWindow: 32768 }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("stays dormant until configured and stores URL plus optional key", async () => {
|
||||
const { provider } = createLlamaProvider();
|
||||
const auth = provider.auth.apiKey!;
|
||||
|
||||
Reference in New Issue
Block a user