mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-10 01:58:31 +00:00
test(llm): verify generate reducer law (#34418)
This commit is contained in:
parent
c3637753bc
commit
b0151e1d02
1 changed files with 8 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { describe, expect } from "bun:test"
|
||||
import { Effect, Schema, Stream } from "effect"
|
||||
import { LLM } from "../src"
|
||||
import { LLM, LLMResponse } from "../src"
|
||||
import { Route, Endpoint, LLMClient, Protocol, type FramingDef } from "../src/route"
|
||||
import { Model } from "../src/schema"
|
||||
import { testEffect } from "./lib/effect"
|
||||
|
|
@ -112,9 +112,15 @@ describe("llm route", () => {
|
|||
const llm = yield* LLMClient.Service
|
||||
const events = Array.from(yield* llm.stream(request).pipe(Stream.runCollect))
|
||||
const response = yield* llm.generate(request)
|
||||
const reduced = LLMResponse.fromEvents(events)
|
||||
|
||||
expect(events.map((event) => event.type)).toEqual(["text-delta", "finish"])
|
||||
expect(response.events.map((event) => event.type)).toEqual(["text-delta", "finish"])
|
||||
expect(reduced).toBeDefined()
|
||||
if (!reduced) throw new Error("stream reducer did not produce a completed response")
|
||||
expect(response.events).toEqual(events)
|
||||
expect(response.message).toEqual(reduced.message)
|
||||
expect(response.usage).toEqual(reduced.usage)
|
||||
expect(response.finishReason).toEqual(reduced.finishReason)
|
||||
expect(response.message.content).toEqual([{ type: "text", text: 'echo:{"body":"hello"}' }])
|
||||
}),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue