Skip to content

Commit 5ed047a

Browse files
authored
feat(js): Adds time to first token for new AI SDK wrapper (langchain-ai#1930)
1 parent 29fb188 commit 5ed047a

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "langsmith",
3-
"version": "0.3.58",
3+
"version": "0.3.59",
44
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
55
"packageManager": "yarn@1.22.19",
66
"files": [

js/src/experimental/vercel/middleware.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ export function LangSmithMiddleware(config?: {
186186
const chunks: LanguageModelV2StreamPart[] = [];
187187
const transformStream = new TransformStream({
188188
async transform(chunk: LanguageModelV2StreamPart, controller) {
189+
if (
190+
chunk.type === "tool-input-start" ||
191+
chunk.type === "text-start"
192+
) {
193+
// Only necessary to log the first token event
194+
if (
195+
runTree?.events == null ||
196+
(Array.isArray(runTree.events) && runTree.events.length === 0)
197+
) {
198+
runTree?.addEvent({ name: "new_token" });
199+
}
200+
} else if (chunk.type === "finish") {
201+
runTree?.addEvent({ name: "end" });
202+
}
189203
chunks.push(chunk);
190204
controller.enqueue(chunk);
191205
},

js/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
2020
export { getDefaultProjectName } from "./utils/project.js";
2121

2222
// Update using yarn bump-version
23-
export const __version__ = "0.3.58";
23+
export const __version__ = "0.3.59";

0 commit comments

Comments
 (0)