(
token: string,
idx?: NewTokenIndices,
runId?: string,
parentRunId?: string,
tags?: string[],
fields?: HandleLLMNewTokenCallbackFields
)
| 364 | } |
| 365 | |
| 366 | handleLLMNewToken( |
| 367 | token: string, |
| 368 | idx?: NewTokenIndices, |
| 369 | runId?: string, |
| 370 | parentRunId?: string, |
| 371 | tags?: string[], |
| 372 | fields?: HandleLLMNewTokenCallbackFields |
| 373 | ): void | Promise<void> { |
| 374 | if (this.skipK === 0) { |
| 375 | if (!this.isLLMStarted) { |
| 376 | this.isLLMStarted = true |
| 377 | if (this.sseStreamer) { |
| 378 | this.sseStreamer.streamStartEvent(this.chatId, token) |
| 379 | } |
| 380 | } |
| 381 | if (this.sseStreamer) { |
| 382 | if (token) { |
| 383 | const chunk = fields?.chunk as ChatGenerationChunk |
| 384 | const message = chunk?.message as AIMessageChunk |
| 385 | const toolCalls = message?.tool_call_chunks || [] |
| 386 | |
| 387 | // Only stream when token is not empty and not a tool call |
| 388 | if (toolCalls.length === 0) { |
| 389 | this.sseStreamer.streamTokenEvent(this.chatId, token) |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | handleLLMEnd() { |
| 397 | if (this.sseStreamer) { |
no test coverage detected