-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made traces work with streaming in the AI SDK
- Loading branch information
1 parent
bb16cd5
commit 7307a99
Showing
4 changed files
with
148 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"evalite": patch | ||
--- | ||
|
||
Made traceAISDKModel work with streamText. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/evalite-tests/tests/fixtures/ai-sdk-traces-stream/traces.eval.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { streamText } from "ai"; | ||
import { MockLanguageModelV1, simulateReadableStream } from "ai/test"; | ||
import { Levenshtein } from "autoevals"; | ||
import { evalite } from "evalite"; | ||
import { traceAISDKModel } from "evalite/ai-sdk"; | ||
|
||
const model = new MockLanguageModelV1({ | ||
doStream: async () => ({ | ||
stream: simulateReadableStream({ | ||
chunks: [ | ||
{ type: "text-delta", textDelta: "Hello" }, | ||
{ type: "text-delta", textDelta: ", " }, | ||
{ type: "text-delta", textDelta: `world!` }, | ||
{ | ||
type: "finish", | ||
finishReason: "stop", | ||
logprobs: undefined, | ||
usage: { completionTokens: 10, promptTokens: 3 }, | ||
}, | ||
], | ||
}), | ||
rawCall: { rawPrompt: null, rawSettings: {} }, | ||
}), | ||
}); | ||
|
||
const tracedModel = traceAISDKModel(model); | ||
|
||
evalite("AI SDK Traces", { | ||
data: () => { | ||
return [ | ||
{ | ||
input: "abc", | ||
expected: "abcdef", | ||
}, | ||
]; | ||
}, | ||
task: async (input) => { | ||
const result = await streamText({ | ||
model: tracedModel, | ||
system: "Test system", | ||
prompt: input, | ||
}); | ||
return result.textStream; | ||
}, | ||
scorers: [Levenshtein], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters