From 2fc1aec8ab357e70ffdbba31aa85d435b37e5b7a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 21 Mar 2023 19:18:44 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/7714 --- app/src/config/AI.ts | 52 +++++++++++++++++++++++++++++++++++----- app/src/types/index.d.ts | 9 +++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/app/src/config/AI.ts b/app/src/config/AI.ts index af4b098bc..32da67e22 100644 --- a/app/src/config/AI.ts +++ b/app/src/config/AI.ts @@ -1,24 +1,64 @@ +import {fetchPost} from "../util/fetch"; export const AI = { element: undefined as Element, genHTML: () => { return ` + + +`; }, bindEvent: () => { + AI.element.querySelectorAll("input").forEach((item) => { + item.addEventListener("change", () => { + fetchPost("/api/setting/setAI", { + openAI: { + apiBaseURL: (AI.element.querySelector("#apiBaseURL") as HTMLInputElement).checked, + apiKey: (AI.element.querySelector("#apiKey") as HTMLInputElement).value, + apiMaxTokens: (AI.element.querySelector("#apiMaxTokens") as HTMLInputElement).value, + apiProxy: (AI.element.querySelector("#apiProxy") as HTMLInputElement).checked, + apiTimeout: (AI.element.querySelector("#apiTimeout") as HTMLInputElement).checked, + } + }, response => { + window.siyuan.config.ai = response.data; + }); + }); + }); }, }; diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index fc4570115..a18373a27 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -392,6 +392,15 @@ declare interface IConfig { repo: { key: string }, + ai: { + openAI: { + apiBaseURL: string + apiKey: string + apiMaxTokens: number + apiProxy: string + apiTimeout: number + }, + } sync: { generateConflictDoc: boolean enabled: boolean