[PR #681] [MERGED] refactor: use event.reason, remove parentEvent #985

Closed
opened 2026-02-15 21:16:10 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/run-llama/LlamaIndexTS/pull/681
Author: @himself65
Created: 4/1/2024
Status: Merged
Merged: 4/1/2024
Merged by: @yisding

Base: mainHead: himself65/20240401/llm-stream


📝 Commits (2)

  • f66f705 refactor: remove parentEvent (step 1)
  • caef936 feat: support event.reason.computedCallers

📊 Changes

30 files changed (+226 additions, -349 deletions)

View changed files

📝 examples/chatHistory.ts (+12 -1)
📝 packages/core/src/GlobalsHelper.ts (+0 -40)
📝 packages/core/src/Retriever.ts (+0 -5)
📝 packages/core/src/agent/openai/worker.ts (+1 -1)
📝 packages/core/src/callbacks/CallbackManager.ts (+39 -26)
📝 packages/core/src/cloud/LlamaCloudRetriever.ts (+3 -8)
📝 packages/core/src/engines/chat/CondenseQuestionChatEngine.ts (+2 -1)
📝 packages/core/src/engines/chat/ContextChatEngine.ts (+3 -12)
📝 packages/core/src/engines/chat/DefaultContextGenerator.ts (+1 -11)
📝 packages/core/src/engines/chat/SimpleChatEngine.ts (+2 -0)
📝 packages/core/src/engines/chat/types.ts (+1 -2)
📝 packages/core/src/engines/query/RetrieverQueryEngine.ts (+4 -12)
📝 packages/core/src/engines/query/SubQuestionQueryEngine.ts (+4 -25)
📝 packages/core/src/indices/summary/index.ts (+6 -19)
📝 packages/core/src/indices/vectorStore/index.ts (+4 -10)
packages/core/src/internal/context/EventCaller.ts (+99 -0)
packages/core/src/internal/utils.ts (+7 -0)
📝 packages/core/src/llm/LLM.ts (+16 -40)
📝 packages/core/src/llm/base.ts (+1 -3)
📝 packages/core/src/llm/mistral.ts (+3 -18)

...and 10 more files

📄 Description

Use AsyncLocalStoarge to pass context through async function. You can track who trigger this event by using this

if (process.env.NODE_ENV === "development") {
  Settings.callbackManager.on("llm-end", (event) => {
    console.log("callers chain", event.reason?.computedCallers);
  });
}
callers chain [
  OpenAI {
    model: 'gpt-3.5-turbo',
    temperature: 0.1,
    topP: 1,
    maxTokens: 3072,
    additionalChatOptions: undefined,
    apiKey: undefined,
    maxRetries: 10,
    timeout: 60000,
    session: OpenAISession { openai: [OpenAI] },
    additionalSessionOptions: undefined,
    chat: [Function (anonymous)],
    streamChat: [Function (anonymous)]
  },
  SimpleChatEngine {
    chatHistory: SimpleChatHistory { messages: [], messagesBefore: 0 },
    llm: OpenAI {
      model: 'gpt-3.5-turbo',
      temperature: 0.1,
      topP: 1,
      maxTokens: 3072,
      additionalChatOptions: undefined,
      apiKey: undefined,
      maxRetries: 10,
      timeout: 60000,
      session: [OpenAISession],
      additionalSessionOptions: undefined,
      chat: [Function (anonymous)],
      streamChat: [Function (anonymous)]
    },
    chat: [Function (anonymous)]
  }
]

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/run-llama/LlamaIndexTS/pull/681 **Author:** [@himself65](https://github.com/himself65) **Created:** 4/1/2024 **Status:** ✅ Merged **Merged:** 4/1/2024 **Merged by:** [@yisding](https://github.com/yisding) **Base:** `main` ← **Head:** `himself65/20240401/llm-stream` --- ### 📝 Commits (2) - [`f66f705`](https://github.com/run-llama/LlamaIndexTS/commit/f66f705e1282a5bd52c6f419e17ff3208e2182e3) refactor: remove parentEvent (step 1) - [`caef936`](https://github.com/run-llama/LlamaIndexTS/commit/caef93601f53c8d911fea9d2dbab7756a54ce054) feat: support `event.reason.computedCallers` ### 📊 Changes **30 files changed** (+226 additions, -349 deletions) <details> <summary>View changed files</summary> 📝 `examples/chatHistory.ts` (+12 -1) 📝 `packages/core/src/GlobalsHelper.ts` (+0 -40) 📝 `packages/core/src/Retriever.ts` (+0 -5) 📝 `packages/core/src/agent/openai/worker.ts` (+1 -1) 📝 `packages/core/src/callbacks/CallbackManager.ts` (+39 -26) 📝 `packages/core/src/cloud/LlamaCloudRetriever.ts` (+3 -8) 📝 `packages/core/src/engines/chat/CondenseQuestionChatEngine.ts` (+2 -1) 📝 `packages/core/src/engines/chat/ContextChatEngine.ts` (+3 -12) 📝 `packages/core/src/engines/chat/DefaultContextGenerator.ts` (+1 -11) 📝 `packages/core/src/engines/chat/SimpleChatEngine.ts` (+2 -0) 📝 `packages/core/src/engines/chat/types.ts` (+1 -2) 📝 `packages/core/src/engines/query/RetrieverQueryEngine.ts` (+4 -12) 📝 `packages/core/src/engines/query/SubQuestionQueryEngine.ts` (+4 -25) 📝 `packages/core/src/indices/summary/index.ts` (+6 -19) 📝 `packages/core/src/indices/vectorStore/index.ts` (+4 -10) ➕ `packages/core/src/internal/context/EventCaller.ts` (+99 -0) ➕ `packages/core/src/internal/utils.ts` (+7 -0) 📝 `packages/core/src/llm/LLM.ts` (+16 -40) 📝 `packages/core/src/llm/base.ts` (+1 -3) 📝 `packages/core/src/llm/mistral.ts` (+3 -18) _...and 10 more files_ </details> ### 📄 Description Use `AsyncLocalStoarge` to pass context through async function. You can track who trigger this event by using this ```ts if (process.env.NODE_ENV === "development") { Settings.callbackManager.on("llm-end", (event) => { console.log("callers chain", event.reason?.computedCallers); }); } ``` ```shell callers chain [ OpenAI { model: 'gpt-3.5-turbo', temperature: 0.1, topP: 1, maxTokens: 3072, additionalChatOptions: undefined, apiKey: undefined, maxRetries: 10, timeout: 60000, session: OpenAISession { openai: [OpenAI] }, additionalSessionOptions: undefined, chat: [Function (anonymous)], streamChat: [Function (anonymous)] }, SimpleChatEngine { chatHistory: SimpleChatHistory { messages: [], messagesBefore: 0 }, llm: OpenAI { model: 'gpt-3.5-turbo', temperature: 0.1, topP: 1, maxTokens: 3072, additionalChatOptions: undefined, apiKey: undefined, maxRetries: 10, timeout: 60000, session: [OpenAISession], additionalSessionOptions: undefined, chat: [Function (anonymous)], streamChat: [Function (anonymous)] }, chat: [Function (anonymous)] } ] ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 21:16:10 -05:00
yindo closed this issue 2026-02-15 21:16:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/LlamaIndexTS#985