Переглянути джерело

:sparkles: 桌面端接入 OpenAI Chat API https://github.com/siyuan-note/siyuan/issues/7560

Liang Ding 2 роки тому
батько
коміт
9a67ec3c09

+ 2 - 1
app/appearance/langs/en_US.json

@@ -1100,6 +1100,7 @@
     "189": "Cloud sync directory is still locked by other devices, please try again later",
     "190": "A problem was found while validating the index, which has been automatically fixed",
     "191": "[%d/%d] Created historical data index",
-    "192": "Rebuilding historical data index, please wait..."
+    "192": "Rebuilding historical data index, please wait...",
+    "193": "Please refer to the [Artificial Intelligence] chapter of the User Guide for configuration"
   }
 }

+ 2 - 1
app/appearance/langs/es_ES.json

@@ -1100,6 +1100,7 @@
     "189": "El directorio de sincronización en la nube todavía está bloqueado por otros dispositivos, inténtalo de nuevo más tarde",
     "190": "Se encontro un problema al validar el indice, el cual se soluciono automaticamente",
     "191": "[%d/%d] Índice de datos históricos creado",
-    "192": "Reconstruyendo el índice de datos históricos, espere..."
+    "192": "Reconstruyendo el índice de datos históricos, espere...",
+    "193": "Consulte el capítulo [Inteligencia artificial] de la guía del usuario para la configuración"
   }
 }

+ 2 - 1
app/appearance/langs/fr_FR.json

@@ -1100,6 +1100,7 @@
     "189": "Le répertoire de synchronisation cloud est toujours verrouillé par d'autres appareils, veuillez réessayer plus tard",
     "190": "Un problème a été trouvé lors de la validation de l'index, qui a été automatiquement corrigé",
     "191": "[%d/%d] Création d'un index de données historiques",
-    "192": "Reconstruction de l'index des données historiques, veuillez patienter..."
+    "192": "Reconstruction de l'index des données historiques, veuillez patienter...",
+    "193": "Veuillez vous référer au chapitre [Intelligence Artificielle] du guide de l'utilisateur pour la configuration"
   }
 }

+ 2 - 1
app/appearance/langs/zh_CHT.json

@@ -1100,6 +1100,7 @@
     "189": "雲端同步目錄還在被其他設備鎖定,請稍後再試",
     "190": "校驗索引時發現一個問題,已經自動修復",
     "191": "[%d/%d] 已經建立條歷史數據索引",
-    "192": "正在重建歷史數據索引,請稍等..."
+    "192": "正在重建歷史數據索引,請稍等...",
+    "193": "請先參考用戶指南 [人工智能] 章節進行配置"
   }
 }

+ 2 - 1
app/appearance/langs/zh_CN.json

@@ -1100,6 +1100,7 @@
     "189": "云端同步目录还在被其他设备锁定,请稍后再试",
     "190": "校验索引时发现一个问题,已经自动修复",
     "191": "[%d/%d] 已经建立条历史数据索引",
-    "192": "正在重建历史数据索引,请稍等..."
+    "192": "正在重建历史数据索引,请稍等...",
+    "193": "请先参考用户指南 [人工智能] 章节进行配置"
   }
 }

+ 5 - 1
app/src/protyle/hint/index.ts

@@ -569,7 +569,11 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
                     }, (response) => {
                         dialog.destroy();
                         focusByRange(protyle.toolbar.range);
-                        insertHTML(`${inputElement.value}\n\n${response.data}`, protyle, true);
+                        let respContent = "";
+                        if (response.data && "" !== response.data) {
+                            respContent = "\n\n" + response.data;
+                        }
+                        insertHTML(`${inputElement.value}${respContent}`, protyle, true);
                     });
                 });
                 return;

+ 6 - 0
kernel/api/ai.go

@@ -17,6 +17,7 @@
 package api
 
 import (
+	"github.com/siyuan-note/siyuan/kernel/model"
 	"net/http"
 
 	"github.com/88250/gulu"
@@ -34,5 +35,10 @@ func chatGPT(c *gin.Context) {
 	}
 
 	msg := arg["msg"].(string)
+	if "" == util.OpenAIAPIKey {
+		util.PushMsg(model.Conf.Language(193), 5000)
+		return
+	}
+
 	ret.Data = util.ChatGPT(msg)
 }