test(ai): simplify TestLLM setup
This commit is contained in:
parent
8ce850e142
commit
dc819e04cc
5 changed files with 32 additions and 9 deletions
|
|
@ -32,6 +32,8 @@ describe("public exports", () => {
|
|||
expect(Provider.make).toBeFunction()
|
||||
expect(ProviderSubpath.make).toBe(Provider.make)
|
||||
expect(TestLLM.layer).toBeFunction()
|
||||
expect(TestLLM.layerWithClient).toBeFunction()
|
||||
expect(TestLLM.requests).toBeDefined()
|
||||
})
|
||||
|
||||
test("route barrel exposes route-authoring APIs", () => {
|
||||
|
|
|
|||
19
packages/ai/test/testing.test.ts
Normal file
19
packages/ai/test/testing.test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { expect } from "bun:test"
|
||||
import { Effect } from "effect"
|
||||
import { LLM, LLMClient, LLMEvent } from "../src"
|
||||
import { OpenAIChat } from "../src/protocols"
|
||||
import { TestLLM } from "../src/testing"
|
||||
import { testEffect } from "./lib/effect"
|
||||
|
||||
const model = OpenAIChat.route.model({ id: "test" })
|
||||
const it = testEffect(TestLLM.layerWithClient({ fallback: TestLLM.text("Hello") }))
|
||||
|
||||
it.effect("provides a client and exposes received requests", () =>
|
||||
Effect.gen(function* () {
|
||||
const response = yield* LLMClient.generate(LLM.request({ model, prompt: "Say hello" }))
|
||||
|
||||
expect(response.text).toBe("Hello")
|
||||
expect(response.events.filter(LLMEvent.is.textDelta)).toEqual([{ type: "text-delta", id: "text-0", text: "Hello" }])
|
||||
expect(yield* TestLLM.requests).toHaveLength(1)
|
||||
}),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue