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

Method onLLMStart

packages/components/src/handler.ts:1326–1457  ·  view source on GitHub ↗
(name: string, input: string | BaseMessageLike[], parentIds: ICommonObject)

Source from the content-addressed store, hash-verified

1324 }
1325
1326 async onLLMStart(name: string, input: string | BaseMessageLike[], parentIds: ICommonObject) {
1327 const returnIds: ICommonObject = {
1328 langSmith: {},
1329 langFuse: {},
1330 lunary: {},
1331 langWatch: {},
1332 arize: {},
1333 phoenix: {},
1334 opik: {}
1335 }
1336
1337 if (Object.prototype.hasOwnProperty.call(this.handlers, 'langSmith')) {
1338 const parentRun: RunTree | undefined = this.handlers['langSmith'].chainRun[parentIds['langSmith'].chainRun]
1339
1340 if (parentRun) {
1341 const inputs: any = {}
1342 if (Array.isArray(input)) {
1343 inputs.messages = input
1344 } else {
1345 inputs.prompts = [input]
1346 }
1347 const childLLMRun = await parentRun.createChild({
1348 name,
1349 run_type: 'llm',
1350 inputs
1351 })
1352 await childLLMRun.postRun()
1353 this.handlers['langSmith'].llmRun = { [childLLMRun.id]: childLLMRun }
1354 returnIds['langSmith'].llmRun = childLLMRun.id
1355 }
1356 }
1357
1358 if (Object.prototype.hasOwnProperty.call(this.handlers, 'langFuse')) {
1359 const trace: LangfuseTraceClient | undefined = this.handlers['langFuse'].trace[parentIds['langFuse'].trace]
1360 if (trace) {
1361 const generation = trace.generation({
1362 name,
1363 input: input
1364 })
1365 this.handlers['langFuse'].generation = { [generation.id]: generation }
1366 returnIds['langFuse'].generation = generation.id
1367 }
1368 }
1369
1370 if (Object.prototype.hasOwnProperty.call(this.handlers, 'lunary')) {
1371 const monitor = this.handlers['lunary'].client
1372 const chainEventId: string = this.handlers['lunary'].chainEvent[parentIds['lunary'].chainEvent]
1373
1374 if (monitor && chainEventId) {
1375 const runId = uuidv4()
1376 await monitor.trackEvent('llm', 'start', {
1377 runId,
1378 parentRunId: chainEventId,
1379 name,
1380 input
1381 })
1382 this.handlers['lunary'].llmEvent = { [runId]: runId }
1383 returnIds['lunary'].llmEvent = runId

Callers 4

runMethod · 0.45
runMethod · 0.45
runMethod · 0.45
runMethod · 0.45

Calls 2

stringifyMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected