-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify callback manager (#1027)
- Loading branch information
Showing
21 changed files
with
169 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"llamaindex": patch | ||
"@llamaindex/core": patch | ||
--- | ||
|
||
refactor: move callback manager & llm to core module | ||
|
||
For people who import `llamaindex/llms/base` or `llamaindex/llms/utils`, | ||
use `@llamaindex/core/llms` and `@llamaindex/core/utils` instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@llamaindex/community": patch | ||
--- | ||
|
||
refactor: depends on core pacakge instead of llamaindex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"llamaindex": minor | ||
"@llamaindex/core": minor | ||
--- | ||
|
||
refactor: simplify callback manager | ||
|
||
Change `event.detail.payload` to `event.detail` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { CallbackManager, Settings } from "@llamaindex/core/global"; | ||
import { beforeEach, describe, expect, expectTypeOf, test, vi } from "vitest"; | ||
|
||
declare module "@llamaindex/core/global" { | ||
interface LlamaIndexEventMaps { | ||
test: { | ||
value: number; | ||
}; | ||
} | ||
} | ||
|
||
describe("event system", () => { | ||
beforeEach(() => { | ||
Settings.callbackManager = new CallbackManager(); | ||
}); | ||
|
||
test("type system", () => { | ||
Settings.callbackManager.on("test", (event) => { | ||
const data = event.detail; | ||
expectTypeOf(data).not.toBeAny(); | ||
expectTypeOf(data).toEqualTypeOf<{ | ||
value: number; | ||
}>(); | ||
}); | ||
}); | ||
|
||
test("dispatch event", async () => { | ||
let callback; | ||
Settings.callbackManager.on( | ||
"test", | ||
(callback = vi.fn((event) => { | ||
const data = event.detail; | ||
expect(data.value).toBe(42); | ||
})), | ||
); | ||
|
||
Settings.callbackManager.dispatchEvent("test", { | ||
value: 42, | ||
}); | ||
expect(callback).toHaveBeenCalledTimes(0); | ||
await new Promise((resolve) => process.nextTick(resolve)); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
// rollup doesn't support decorators for now | ||
// test('wrap event caller', async () => { | ||
// class A { | ||
// @wrapEventCaller | ||
// fn() { | ||
// Settings.callbackManager.dispatchEvent('test', { | ||
// value: 42 | ||
// }); | ||
// } | ||
// } | ||
// const a = new A(); | ||
// let callback; | ||
// Settings.callbackManager.on('test', callback = vi.fn((event) => { | ||
// const data = event.detail; | ||
// expect(event.reason!.caller).toBe(a); | ||
// expect(data.value).toBe(42); | ||
// })); | ||
// a.fn(); | ||
// expect(callback).toHaveBeenCalledTimes(0); | ||
// await new Promise((resolve) => process.nextTick(resolve)); | ||
// expect(callback).toHaveBeenCalledTimes(1); | ||
// }) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.