From 6eab583d01c03aaf9b77aef240e2f7d972623b58 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 15 Jun 2024 00:34:59 +0800 Subject: [PATCH] feat: apply ai summary --- src/renderer/src/hono.ts | 132 ++++++++++-------- .../src/modules/entry-content/index.tsx | 26 +++- src/renderer/src/queries/ai.ts | 18 ++- 3 files changed, 114 insertions(+), 62 deletions(-) diff --git a/src/renderer/src/hono.ts b/src/renderer/src/hono.ts index 3d80598451..84b3ef5a3e 100644 --- a/src/renderer/src/hono.ts +++ b/src/renderer/src/hono.ts @@ -95,6 +95,22 @@ declare const routes: hono_hono_base.HonoBase
@@ -94,7 +104,6 @@ function EntryContentRender({ entryId }: { entryId: string }) { new Date(entry.entries.publishedAt).toUTCString()}
- {!content && (
{!error ? ( @@ -107,7 +116,18 @@ function EntryContentRender({ entryId }: { entryId: string }) { )}
)} -
+
+ {(summary.isLoading || summary.data) && ( +
+
+ + AI summary +
+
+ {summary.isLoading ? "Loading..." : summary.data} +
+
+ )} {content}
diff --git a/src/renderer/src/queries/ai.ts b/src/renderer/src/queries/ai.ts index 99e46a7193..c72c180096 100644 --- a/src/renderer/src/queries/ai.ts +++ b/src/renderer/src/queries/ai.ts @@ -66,7 +66,7 @@ export const ai = { const res = await apiClient.ai.translation.$get({ query: { id: entry.entries.id, - language: language as SupportedLanguages, + language, fields: fields?.join(",") || "title", }, }) @@ -75,4 +75,20 @@ export const ai = { return null } }), + summary: ({ + entryId, + language, + }: { + entryId: string + language?: SupportedLanguages + }) => + defineQuery(["summary", entryId, language], async () => { + const res = await apiClient.ai.summary.$get({ + query: { + id: entryId, + language, + }, + }) + return res.data + }), }