Download src/llm/stream.test.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/llm/stream.test.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/llm/stream.test.ts
-
curl -L -o stream.test.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/llm/stream.test.ts
1.98 kB
| import { createApiRegistry, createLlmRuntime } from "@openclaw/ai"; | |
| import type { AssistantMessage, Model } from "@openclaw/llm-core"; | |
| import { describe, expect, it, vi } from "vitest"; | |
| import { createZeroUsageFixture } from "../agents/test-helpers/usage-fixtures.js"; | |
| import { bindModelLlmRuntime } from "./model-runtime-binding.js"; | |
| import { streamSimple } from "./stream.js"; | |
| import { createAssistantMessageEventStream } from "./utils/event-stream.js"; | |
| describe("LLM stream facade", () => { | |
| it("routes a prepared model through its lifecycle runtime", async () => { | |
| const registry = createApiRegistry(); | |
| const runtime = createLlmRuntime(registry); | |
| const expected = createAssistantMessageEventStream(); | |
| const message = { | |
| role: "assistant", | |
| content: [{ type: "text", text: "complete" }], | |
| api: "test-lifecycle-api", | |
| provider: "test-provider", | |
| model: "test-model", | |
| usage: createZeroUsageFixture(), | |
| stopReason: "stop", | |
| timestamp: Date.now(), | |
| } satisfies AssistantMessage; | |
| const providerStream = vi.fn(() => expected); | |
| registry.registerApiProvider({ | |
| api: "test-lifecycle-api", | |
| stream: providerStream, | |
| streamSimple: providerStream, | |
| }); | |
| const model = bindModelLlmRuntime( | |
| { | |
| api: "test-lifecycle-api", | |
| provider: "test-provider", | |
| id: "test-model", | |
| name: "Test Model", | |
| baseUrl: "https://example.test", | |
| reasoning: false, | |
| input: ["text"], | |
| cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, | |
| contextWindow: 1024, | |
| maxTokens: 512, | |
| } satisfies Model, | |
| runtime, | |
| ); | |
| const output = streamSimple(model, { messages: [] }); | |
| expect(providerStream).not.toHaveBeenCalled(); | |
| expected.push({ type: "done", reason: "stop", message }); | |
| expected.end(); | |
| await expect(output.result()).resolves.toEqual(message); | |
| expect(providerStream).toHaveBeenCalledOnce(); | |
| }); | |
| }); | |