mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-02 02:58:10 +02:00
Simplify text completion generator boundary
This commit is contained in:
parent
bfb5494552
commit
b3aaa9a4af
3 changed files with 56 additions and 8 deletions
|
|
@ -0,0 +1,24 @@
|
|||
import { describe, expect, it } from "@effect/vitest";
|
||||
import type { LlmChunk } from "@trustgraph/base";
|
||||
import { providerRuntimeError, toAsyncGenerator } from "../model/text-completion/common.js";
|
||||
|
||||
const emptyChunkIterator = (): AsyncIterable<LlmChunk> => ({
|
||||
[Symbol.asyncIterator]: () => ({
|
||||
next: () => Promise.resolve({ done: true, value: undefined }),
|
||||
}),
|
||||
});
|
||||
|
||||
describe("text completion common helpers", () => {
|
||||
it("maps fallback generator throw failures into tagged provider errors", async () => {
|
||||
const generator = toAsyncGenerator(
|
||||
emptyChunkIterator(),
|
||||
(error) => providerRuntimeError("test-provider", error),
|
||||
);
|
||||
|
||||
await expect(generator.throw("provider failed")).rejects.toMatchObject({
|
||||
_tag: "TextCompletionProviderError",
|
||||
provider: "test-provider",
|
||||
message: "provider failed",
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue