Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: New settings UI https://github.com/siyuan-note/siyuan/issues/17601

Danieldbf076ce9858
diff --git a/app/src/config/ai.ts b/app/src/config/ai.ts
index c68e7f2354..06d2b8249c 100644
--- a/app/src/config/ai.ts
+++ b/app/src/config/ai.ts
@@ -20,8 +20,8 @@ function getDefaultProvider() {
return p;
}
-function getDefaultChat() {
- return window.siyuan.config.ai.chat || {
+function getDefaultEditing() {
+ return window.siyuan.config.ai.editing || {
maxHistoryMessages: 7,
temperature: 1.0,
maxCompletionTokens: 0,
@@ -33,7 +33,7 @@ export const ai = {
genHTML: () => {
const model = getDefaultModel();
const prov = getDefaultProvider();
- const chat = getDefaultChat();
+ const editing = getDefaultEditing();
const agent = window.siyuan.config.ai.agent || {sessionTimeout: 600, confirmTimeout: 120, maxRetries: 3};
let responsiveHTML = "";
/// #if MOBILE
@@ -71,19 +71,19 @@ export const ai = {
<div class="b3-label">
${window.siyuan.languages.apiMaxTokens}
<div class="fn__hr"></div>
- <input class="b3-text-field fn__flex-center fn__block" type="number" step="1" min="0" id="chatMaxCompletionTokens" value="${chat.maxCompletionTokens || 0}"/>
+ <input class="b3-text-field fn__flex-center fn__block" type="number" step="1" min="0" id="chatMaxCompletionTokens" value="${editing.maxCompletionTokens || 0}"/>
<div class="b3-label__text">${window.siyuan.languages.apiMaxTokensTip}</div>
</div>
<div class="b3-label">
${window.siyuan.languages.apiTemperature}
<div class="fn__hr"></div>
- <input class="b3-text-field fn__flex-center fn__block" type="number" step="0.1" min="0" max="2" id="chatTemperature" value="${chat.temperature || 1.0}"/>
+ <input class="b3-text-field fn__flex-center fn__block" type="number" step="0.1" min="0" max="2" id="chatTemperature" value="${editing.temperature || 1.0}"/>
<div class="b3-label__text">${window.siyuan.languages.apiTemperatureTip}</div>
</div>
<div class="b3-label">
${window.siyuan.languages.apiMaxContexts}
<div class="fn__hr"></div>
- <input class="b3-text-field fn__flex-center fn__block" type="number" step="1" min="1" max="64" id="chatMaxHistoryMessages" value="${chat.maxHistoryMessages || 7}"/>
+ <input class="b3-text-field fn__flex-center fn__block" type="number" step="1" min="1" max="64" id="chatMaxHistoryMessages" value="${editing.maxHistoryMessages || 7}"/>
<div class="b3-label__text">${window.siyuan.languages.apiMaxContextsTip}</div>
</div>
<div class="b3-label">
@@ -158,7 +158,7 @@ export const ai = {
<div class="b3-label__text">${window.siyuan.languages.apiMaxTokensTip}</div>
</div>
<span class="fn__space"></span>
- <input class="b3-text-field fn__flex-center fn__size200" type="number" step="1" min="0" id="chatMaxCompletionTokens" value="${chat.maxCompletionTokens || 0}"/>
+ <input class="b3-text-field fn__flex-center fn__size200" type="number" step="1" min="0" id="chatMaxCompletionTokens" value="${editing.maxCompletionTokens || 0}"/>
</div>
<div class="fn__flex b3-label">
<div class="fn__flex-1">
@@ -166,7 +166,7 @@ export const ai = {
<div class="b3-label__text">${window.siyuan.languages.apiTemperatureTip}</div>
</div>
<span class="fn__space"></span>
- <input class="b3-text-field fn__flex-center fn__size200" type="number" step="0.1" min="0" max="2" id="chatTemperature" value="${chat.temperature || 1.0}"/>
+ <input class="b3-text-field fn__flex-center fn__size200" type="number" step="0.1" min="0" max="2" id="chatTemperature" value="${editing.temperature || 1.0}"/>
</div>
<div class="fn__flex b3-label">
<div class="fn__flex-1">
@@ -174,7 +174,7 @@ export const ai = {
<div class="b3-label__text">${window.siyuan.languages.apiMaxContextsTip}</div>
</div>
<span class="fn__space"></span>
- <input class="b3-text-field fn__flex-center fn__size200" type="number" step="1" min="1" max="64" id="chatMaxHistoryMessages" value="${chat.maxHistoryMessages || 7}"/>
+ <input class="b3-text-field fn__flex-center fn__size200" type="number" step="1" min="1" max="64" id="chatMaxHistoryMessages" value="${editing.maxHistoryMessages || 7}"/>
</div>
<div class="fn__flex b3-label">
<div class="fn__flex-1">
@@ -232,7 +232,7 @@ export const ai = {
models: [] as Config.IModel[],
};
const firstModel = firstProvider.models[0] ?? {id: "", name: "", enabled: true};
- const chat = window.siyuan.config.ai.chat;
+ const editing = window.siyuan.config.ai.editing;
fetchPost("/api/setting/setAI", {
providers: [{
id: firstProvider.id,
@@ -246,10 +246,10 @@ export const ai = {
name: (ai.element.querySelector("#apiModel") as HTMLInputElement)?.value || firstModel.name || "",
}]
}],
- chat: {
+ editing: {
maxCompletionTokens: parseInt((ai.element.querySelector("#chatMaxCompletionTokens") as HTMLInputElement)?.value) || 0,
- temperature: parseFloat((ai.element.querySelector("#chatTemperature") as HTMLInputElement)?.value) || chat.temperature || 1.0,
- maxHistoryMessages: parseInt((ai.element.querySelector("#chatMaxHistoryMessages") as HTMLInputElement)?.value) || chat.maxHistoryMessages || 7,
+ temperature: parseFloat((ai.element.querySelector("#chatTemperature") as HTMLInputElement)?.value) || editing.temperature || 1.0,
+ maxHistoryMessages: parseInt((ai.element.querySelector("#chatMaxHistoryMessages") as HTMLInputElement)?.value) || editing.maxHistoryMessages || 7,
},
agent: {
sessionTimeout: parseInt((ai.element.querySelector("#agentTimeout") as HTMLInputElement)?.value) || 600,
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index 33f98c180c..ab3cee8098 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -115,7 +115,7 @@ declare namespace Config {
*/
export interface IAI {
providers: IProvider[];
- chat: IChat;
+ editing: IEditing;
agent: IAgent;
mcp: IMCP;
embedding: IEmbedding;
@@ -135,9 +135,9 @@ declare namespace Config {
}
/**
- * AI chat scenario behavior settings (mirrors IAgent)
+ * AI in-editor chat scenario behavior settings (mirrors IAgent)
*/
- export interface IChat {
+ export interface IEditing {
modelId: string;
maxHistoryMessages: number;
temperature: number;
@@ -171,7 +171,7 @@ declare namespace Config {
/**
* AI model configuration. Behavior params (maxTokens/temperature/maxContexts)
- * live on IChat; Model holds only identity fields.
+ * live on IEditing; Model holds only identity fields.
*/
export interface IModel {
id: string;
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index d42ec09b1b..81baa5ce15 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -207,15 +207,15 @@ func setAI(c *gin.Context) {
}
}
- if nil != ai.Chat {
- if 0 > ai.Chat.MaxCompletionTokens {
- ai.Chat.MaxCompletionTokens = 0
+ if nil != ai.Editing {
+ if 0 > ai.Editing.MaxCompletionTokens {
+ ai.Editing.MaxCompletionTokens = 0
}
- if 0 > ai.Chat.Temperature || 2 < ai.Chat.Temperature {
- ai.Chat.Temperature = 1.0
+ if 0 > ai.Editing.Temperature || 2 < ai.Editing.Temperature {
+ ai.Editing.Temperature = 1.0
}
- if 1 > ai.Chat.MaxHistoryMessages || 64 < ai.Chat.MaxHistoryMessages {
- ai.Chat.MaxHistoryMessages = 7
+ if 1 > ai.Editing.MaxHistoryMessages || 64 < ai.Editing.MaxHistoryMessages {
+ ai.Editing.MaxHistoryMessages = 7
}
}
@@ -231,8 +231,8 @@ func setAI(c *gin.Context) {
if nil == ai.Agent {
ai.Agent = model.Conf.AI.Agent
}
- if nil == ai.Chat {
- ai.Chat = model.Conf.AI.Chat
+ if nil == ai.Editing {
+ ai.Editing = model.Conf.AI.Editing
}
for i, p := range ai.Providers {
diff --git a/kernel/conf/ai.go b/kernel/conf/ai.go
index da1b7a4e75..b97f5b3f3d 100644
--- a/kernel/conf/ai.go
+++ b/kernel/conf/ai.go
@@ -30,7 +30,7 @@ type AI struct {
MCP *MCP `json:"mcp"`
Embedding *Embedding `json:"embedding"`
Agent *Agent `json:"agent"`
- Chat *Chat `json:"chat"`
+ Editing *Editing `json:"editing"`
Providers []*Provider `json:"providers"`
}
@@ -44,10 +44,10 @@ type Agent struct {
MaxToolCallRounds int `json:"maxToolCallRounds"`
}
-// Chat holds behavior parameters used by the chat scenario. They are kept
-// here (instead of on Model) to mirror Agent and to decouple scenario behavior
-// from the model registry. See https://github.com/siyuan-note/siyuan/issues/17797
-type Chat struct {
+// Editing holds behavior parameters used by the in-editor chat scenario. They
+// are kept here (instead of on Model) to mirror Agent and to decouple scenario
+// behavior from the model registry. See https://github.com/siyuan-note/siyuan/issues/17797
+type Editing struct {
ModelID string `json:"modelId"`
MaxHistoryMessages int `json:"maxHistoryMessages"` // Max number of prior turns kept as context
Temperature float64 `json:"temperature"` // Alignment with Agent.Temperature
@@ -75,7 +75,7 @@ type Provider struct {
// Model is the provider-scoped model registry entry. MaxTokens/Temperature/
// MaxContexts remain the persisted UI-facing config (the settings page still
-// reads/writes them). Chat holds the runtime view derived from them.
+// reads/writes them). Editing holds the runtime view derived from them.
type Model struct {
ID string `json:"id"`
DisplayName string `json:"displayName,omitempty"`
@@ -115,7 +115,7 @@ func NewAI() *AI {
MaxCompletionTokens: 0,
MaxToolCallRounds: 64,
},
- Chat: &Chat{
+ Editing: &Editing{
MaxHistoryMessages: 7,
Temperature: 1.0,
MaxCompletionTokens: 0,
@@ -145,17 +145,17 @@ func NewAI() *AI {
}
if maxTokens := os.Getenv("SIYUAN_OPENAI_API_MAX_TOKENS"); "" != maxTokens {
if v, err := strconv.Atoi(maxTokens); err == nil {
- ai.Chat.MaxCompletionTokens = v
+ ai.Editing.MaxCompletionTokens = v
}
}
if temperature := os.Getenv("SIYUAN_OPENAI_API_TEMPERATURE"); "" != temperature {
if v, err := strconv.ParseFloat(temperature, 64); err == nil {
- ai.Chat.Temperature = v
+ ai.Editing.Temperature = v
}
}
if maxContexts := os.Getenv("SIYUAN_OPENAI_API_MAX_CONTEXTS"); "" != maxContexts {
if v, err := strconv.Atoi(maxContexts); err == nil {
- ai.Chat.MaxHistoryMessages = v
+ ai.Editing.MaxHistoryMessages = v
}
}
@@ -263,11 +263,11 @@ func (ai *AI) GetModel(id string) (*Provider, *Model) {
return nil, nil
}
-func (ai *AI) GetChatModel() (*Provider, *Model) {
- if ai.Chat == nil || ai.Chat.ModelID == "" {
+func (ai *AI) GetEditingModel() (*Provider, *Model) {
+ if ai.Editing == nil || ai.Editing.ModelID == "" {
return nil, nil
}
- return ai.GetModel(ai.Chat.ModelID)
+ return ai.GetModel(ai.Editing.ModelID)
}
func (ai *AI) GetAgentModel() (*Provider, *Model) {
@@ -403,7 +403,7 @@ func MigrateAI(data []byte) *AI {
}
maxContexts := getInt(oai, "apiMaxContexts")
- ai.Chat = &Chat{
+ ai.Editing = &Editing{
MaxHistoryMessages: maxContexts,
Temperature: getFloat(oai, "apiTemperature"),
MaxCompletionTokens: getInt(oai, "apiMaxTokens"),
@@ -439,7 +439,7 @@ func MigrateAI(data []byte) *AI {
}
func assignDefaultModelIDs(ai *AI) {
- if (ai.Chat != nil && ai.Chat.ModelID != "") || (ai.Agent != nil && ai.Agent.ModelID != "") {
+ if (ai.Editing != nil && ai.Editing.ModelID != "") || (ai.Agent != nil && ai.Agent.ModelID != "") {
return
}
var m *Model
@@ -463,11 +463,11 @@ func assignDefaultModelIDs(ai *AI) {
if m == nil || m.ID == "" {
return
}
- if ai.Chat == nil {
- ai.Chat = &Chat{}
+ if ai.Editing == nil {
+ ai.Editing = &Editing{}
}
- if ai.Chat.ModelID == "" {
- ai.Chat.ModelID = m.ID
+ if ai.Editing.ModelID == "" {
+ ai.Editing.ModelID = m.ID
}
if ai.Agent == nil {
ai.Agent = &Agent{MaxToolCallRounds: 64}
diff --git a/kernel/model/ai.go b/kernel/model/ai.go
index 04c0d564ee..e813c8c665 100644
--- a/kernel/model/ai.go
+++ b/kernel/model/ai.go
@@ -86,20 +86,20 @@ func chatGPTComplete(msg string, contextMsgs []string, cloud bool) (ret string,
util.PushEndlessProgress("Requesting...")
defer util.ClearPushProgress(100)
- prov, m := Conf.AI.GetChatModel()
+ prov, m := Conf.AI.GetEditingModel()
if nil == prov || nil == m {
err = errors.New("no AI provider configured")
return
}
- chat := Conf.AI.Chat
- if nil == chat {
- err = errors.New("no AI chat config")
+ editing := Conf.AI.Editing
+ if nil == editing {
+ err = errors.New("no AI editing config")
return
}
- if chat.MaxHistoryMessages < len(contextMsgs) {
- contextMsgs = contextMsgs[len(contextMsgs)-chat.MaxHistoryMessages:]
+ if editing.MaxHistoryMessages < len(contextMsgs) {
+ contextMsgs = contextMsgs[len(contextMsgs)-editing.MaxHistoryMessages:]
}
var gpt GPT
@@ -110,8 +110,8 @@ func chatGPTComplete(msg string, contextMsgs []string, cloud bool) (ret string,
c: util.NewOpenAIClient(prov.APIKey, prov.BaseURL),
m: m,
timeout: prov.RequestTimeout,
- maxCompletionTokens: chat.MaxCompletionTokens,
- temperature: chat.Temperature,
+ maxCompletionTokens: editing.MaxCompletionTokens,
+ temperature: editing.Temperature,
}
}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 3a2c048906..99f1c6582a 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -601,8 +601,8 @@ func InitConf() {
MaxToolCallRounds: 64,
}
}
- if nil == Conf.AI.Chat {
- Conf.AI.Chat = &conf.Chat{
+ if nil == Conf.AI.Editing {
+ Conf.AI.Editing = &conf.Editing{
MaxHistoryMessages: 7,
Temperature: 1.0,
MaxCompletionTokens: 0,
@@ -616,14 +616,14 @@ func InitConf() {
p.RequestTimeout = 30
}
}
- if 0 > Conf.AI.Chat.MaxCompletionTokens {
- Conf.AI.Chat.MaxCompletionTokens = 0
+ if 0 > Conf.AI.Editing.MaxCompletionTokens {
+ Conf.AI.Editing.MaxCompletionTokens = 0
}
- if 0 > Conf.AI.Chat.Temperature || 2 < Conf.AI.Chat.Temperature {
- Conf.AI.Chat.Temperature = 1.0
+ if 0 > Conf.AI.Editing.Temperature || 2 < Conf.AI.Editing.Temperature {
+ Conf.AI.Editing.Temperature = 1.0
}
- if 1 > Conf.AI.Chat.MaxHistoryMessages || 64 < Conf.AI.Chat.MaxHistoryMessages {
- Conf.AI.Chat.MaxHistoryMessages = 7
+ if 1 > Conf.AI.Editing.MaxHistoryMessages || 64 < Conf.AI.Editing.MaxHistoryMessages {
+ Conf.AI.Editing.MaxHistoryMessages = 7
}
for _, p := range Conf.AI.Providers {
@@ -644,9 +644,9 @@ func InitConf() {
p.BaseURL,
p.RequestTimeout,
m.Name,
- Conf.AI.Chat.MaxCompletionTokens,
- Conf.AI.Chat.Temperature,
- Conf.AI.Chat.MaxHistoryMessages)
+ Conf.AI.Editing.MaxCompletionTokens,
+ Conf.AI.Editing.Temperature,
+ Conf.AI.Editing.MaxHistoryMessages)
}
}