aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-09-29 23:43:10 +0000
committerMohamedBassem <me@mbassem.com>2024-09-29 23:43:10 +0000
commit5281531d6f4aab4605c407d5167dd8e44f237f0d (patch)
tree0bb076de0538952e09b31c946a79923b35aa6996
parent8fe1927323b5e44354f43a5c1243fcd49c02f762 (diff)
downloadkarakeep-5281531d6f4aab4605c407d5167dd8e44f237f0d.tar.zst
feature(web): Add ability to rerun inference on all bookmarks. Fixes 443
-rw-r--r--apps/web/components/dashboard/admin/AdminActions.tsx24
-rw-r--r--packages/trpc/routers/admin.ts11
2 files changed, 35 insertions, 0 deletions
diff --git a/apps/web/components/dashboard/admin/AdminActions.tsx b/apps/web/components/dashboard/admin/AdminActions.tsx
index 783f7e76..dfdf65eb 100644
--- a/apps/web/components/dashboard/admin/AdminActions.tsx
+++ b/apps/web/components/dashboard/admin/AdminActions.tsx
@@ -35,6 +35,23 @@ export default function AdminActions() {
},
});
+ const {
+ mutate: reRunInferenceOnAllBookmarks,
+ isPending: isInferencePending,
+ } = api.admin.reRunInferenceOnAllBookmarks.useMutation({
+ onSuccess: () => {
+ toast({
+ description: "Inference jobs enqueued",
+ });
+ },
+ onError: (e) => {
+ toast({
+ variant: "destructive",
+ description: e.message,
+ });
+ },
+ });
+
return (
<div>
<div className="mb-2 mt-8 text-xl font-medium">Actions</div>
@@ -68,6 +85,13 @@ export default function AdminActions() {
</ActionButton>
<ActionButton
variant="destructive"
+ loading={isInferencePending}
+ onClick={() => reRunInferenceOnAllBookmarks()}
+ >
+ Regenerate AI Tags for All Bookmarks
+ </ActionButton>
+ <ActionButton
+ variant="destructive"
loading={isReindexPending}
onClick={() => reindexBookmarks()}
>
diff --git a/packages/trpc/routers/admin.ts b/packages/trpc/routers/admin.ts
index 14cb4ac9..b3fb2383 100644
--- a/packages/trpc/routers/admin.ts
+++ b/packages/trpc/routers/admin.ts
@@ -132,4 +132,15 @@ export const adminAppRouter = router({
await Promise.all(bookmarkIds.map((b) => triggerSearchReindex(b.id)));
}),
+ reRunInferenceOnAllBookmarks: adminProcedure.mutation(async ({ ctx }) => {
+ const bookmarkIds = await ctx.db.query.bookmarks.findMany({
+ columns: {
+ id: true,
+ },
+ });
+
+ await Promise.all(
+ bookmarkIds.map((b) => OpenAIQueue.enqueue({ bookmarkId: b.id })),
+ );
+ }),
});