-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add provider abstraction and time provider
- Loading branch information
Showing
13 changed files
with
198 additions
and
38 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
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
File renamed without changes.
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
export * from "./actions"; | ||
export * from "./actions/index"; | ||
export * from "./context"; | ||
export * from "./evaluation"; | ||
export * from "./evaluators"; | ||
export * from "./evaluators/index"; | ||
export * from "./goals"; | ||
export * from "./lore"; | ||
export * from "./memory"; | ||
export * from "./messages"; | ||
export * from "./providers"; | ||
export * from "./relationships"; | ||
export * from "./runtime"; | ||
export * from "./types"; |
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,20 @@ | ||
import time from "./providers/time"; | ||
import { BgentRuntime } from "./runtime"; | ||
import { type Message, type Provider } from "./types"; | ||
|
||
export const defaultProviders: Provider[] = [time]; | ||
|
||
/** | ||
* Formats provider outputs into a string which can be injected into the context. | ||
* @param providers - An array of evaluator objects. | ||
* @returns A string that concatenates the outputs of each provider. | ||
*/ | ||
export async function getProviders(runtime: BgentRuntime, message: Message) { | ||
const providerResults = await Promise.all( | ||
runtime.providers.map(async (provider) => { | ||
return await provider.get(runtime, message); | ||
}), | ||
); | ||
|
||
return providerResults.join("\n"); | ||
} |
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,89 @@ | ||
import { type UUID } from "crypto"; | ||
import dotenv from "dotenv"; | ||
import { createRuntime } from "../../../test/createRuntime"; | ||
import { composeContext } from "../../context"; | ||
import { BgentRuntime } from "../../runtime"; | ||
|
||
import { type Message, type State } from "../../types"; | ||
import timeProvider from "../time"; | ||
|
||
dotenv.config({ path: ".dev.vars" }); | ||
|
||
const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; | ||
|
||
describe("Time Provider", () => { | ||
let runtime: BgentRuntime; | ||
let user: { id: UUID }; | ||
let room_id: UUID; | ||
|
||
beforeAll(async () => { | ||
const setup = await createRuntime({ | ||
env: process.env as Record<string, string>, | ||
providers: [timeProvider], | ||
}); | ||
runtime = setup.runtime; | ||
user = { id: setup.session.user?.id as UUID }; | ||
room_id = "some-room-id" as UUID; // Assume room_id is fetched or set up in your environment | ||
}); | ||
|
||
test("Time provider should return the current time in the correct format", async () => { | ||
const message: Message = { | ||
senderId: user.id, | ||
agentId: zeroUuid, | ||
userIds: [user.id, zeroUuid], | ||
content: { content: "" }, | ||
room_id: room_id, | ||
}; | ||
|
||
const currentTimeResponse = await timeProvider.get( | ||
runtime, | ||
message, | ||
{} as State, | ||
); | ||
expect(currentTimeResponse).toMatch( | ||
/^The current time is: \d{1,2}:\d{2}:\d{2}\s?(AM|PM)$/, | ||
); | ||
}); | ||
|
||
test("Time provider should be integrated in the state and context correctly", async () => { | ||
const message: Message = { | ||
senderId: user.id, | ||
agentId: zeroUuid, | ||
userIds: [user.id, zeroUuid], | ||
content: { content: "" }, | ||
room_id: room_id, | ||
}; | ||
|
||
// Manually integrate the time provider's response into the state | ||
const state = await runtime.composeState(message); | ||
|
||
const contextTemplate = `Current Time: {{providers}}`; | ||
const context = composeContext({ | ||
state: state, | ||
template: contextTemplate, | ||
}); | ||
|
||
const match = context.match( | ||
new RegExp( | ||
`^Current Time: The current time is: \\d{1,2}:\\d{2}:\\d{2}\\s?(AM|PM)$`, | ||
), | ||
); | ||
|
||
expect(match).toBeTruthy(); | ||
}); | ||
|
||
test("Time provider should work independently", async () => { | ||
const message: Message = { | ||
senderId: user.id, | ||
agentId: zeroUuid, | ||
userIds: [user.id, zeroUuid], | ||
content: { content: "" }, | ||
room_id: room_id, | ||
}; | ||
const currentTimeResponse = await timeProvider.get(runtime, message); | ||
|
||
expect(currentTimeResponse).toMatch( | ||
/^The current time is: \d{1,2}:\d{2}:\d{2}\s?(AM|PM)$/, | ||
); | ||
}); | ||
}); |
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 @@ | ||
export { default as summarization } from "./time"; |
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,12 @@ | ||
import { type BgentRuntime } from "../runtime"; | ||
import { type Message, type Provider, type State } from "../types"; | ||
|
||
const time: Provider = { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
get: async (_runtime: BgentRuntime, _message: Message, _state?: State) => { | ||
const currentTime = new Date().toLocaleTimeString("en-US"); | ||
return "The current time is: " + currentTime; | ||
}, | ||
}; | ||
|
||
export default time; |
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
Oops, something went wrong.