MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / handleLLMNewToken

Method handleLLMNewToken

packages/components/src/handler.ts:366–394  ·  view source on GitHub ↗
(
        token: string,
        idx?: NewTokenIndices,
        runId?: string,
        parentRunId?: string,
        tags?: string[],
        fields?: HandleLLMNewTokenCallbackFields
    )

Source from the content-addressed store, hash-verified

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) {

Callers 6

generateMethod · 0.80
_generateMethod · 0.80
_streamResponseChunksMethod · 0.80
_streamResponseChunksMethod · 0.80
_streamResponseChunksMethod · 0.80
_streamResponseChunksMethod · 0.80

Calls 2

streamStartEventMethod · 0.65
streamTokenEventMethod · 0.65

Tested by

no test coverage detected