Closed justyns closed 6 months ago
Not this is the best way, but there is a system.invokeSpaceFunction syscall now that you could leverage to allow people to write custom JS for this.
One method I was experimenting with was sending an event:
silverbullet.registerEventListener({name: "ai:enrichMessage"}, async (event) => {
console.log("task event:", event, event.data);
let enrichedContent = event.data.enrichedContent;
enrichedContent = `${enrichedContent} BLOOP`;
return {enrichedContent};
});
This actually works pretty well, but only for a single listener.
Another attempt, this one works with multiple functions:
silverbullet.registerFunction('addBloop', async (message) => {
return `${message} BLOOP`;
});
silverbullet.registerFunction('addBlarp', async (message) => {
return `${message} BLARP`;
});
silverbullet.registerEventListener({name: "ai:enrichMessage"}, async (event) => {
return 'addBloop';
});
silverbullet.registerEventListener({name: "ai:enrichMessage"}, async (event) => {
return 'addBlarp';
});
I'm not sure if I like having to define both an event listener and a function, but it does work. Maybe an alternative would be a new silverbullet.registerPlugHook
type of syntax?
I went with the syntax in my last comment, and also added a way to configure them in SETTINGS too to avoid having an eventlistener https://github.com/justyns/silverbullet-ai/pull/26
Similar to #14 but also separate. It'd be nice to allow users to provide their own hook for changing the chat messages that get sent to the llm apis.
For example, a user could create something like: "regex to detect github issue url -> download github issue and summarize it -> add as context to chat message"
Another use case would be to implement #14 itself