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

Daniel70c6af57d194
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index 7ef388d7a9..c45f678580 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -209,15 +209,6 @@ func setAI(c *gin.Context) {
if nil == m {
continue
}
- if 0 > m.MaxTokens {
- m.MaxTokens = 0
- }
- if 0 >= m.Temperature || 2 < m.Temperature {
- m.Temperature = 1.0
- }
- if 1 > m.MaxContexts || 64 < m.MaxContexts {
- m.MaxContexts = 7
- }
}
}
@@ -250,19 +241,6 @@ func setAI(c *gin.Context) {
}
model.Conf.AI = ai
- // Chat is the runtime view of the chat-scenario model's behavior params; the
- // settings page persists them on Model, so mirror them onto Chat after assign.
- // https://github.com/siyuan-note/siyuan/issues/17797
- if _, m := model.Conf.AI.GetScenarioModel(conf.ScenarioChat); nil != m {
- if nil == model.Conf.AI.Chat {
- model.Conf.AI.Chat = &conf.Chat{}
- }
- model.Conf.AI.Chat.MaxCompletionTokens = m.MaxTokens
- model.Conf.AI.Chat.Temperature = m.Temperature
- model.Conf.AI.Chat.MaxHistoryMessages = m.MaxContexts
- model.Conf.AI.Chat.MaxContinueRounds = m.MaxContexts
- }
-
model.Conf.AI.Normalize()
model.Conf.Save()
diff --git a/kernel/conf/ai.go b/kernel/conf/ai.go
index 4f8ece0f92..a353ad9f78 100644
--- a/kernel/conf/ai.go
+++ b/kernel/conf/ai.go
@@ -81,9 +81,6 @@ type Model struct {
DisplayName string `json:"displayName,omitempty"`
Enabled bool `json:"enabled"`
Name string `json:"name"`
- MaxTokens int `json:"maxTokens"`
- Temperature float64 `json:"temperature"`
- MaxContexts int `json:"maxContexts"`
}
const (
@@ -147,28 +144,21 @@ func NewAI() *AI {
}
model := &Model{
- Name: apiModel,
- Temperature: 1.0,
- MaxContexts: 7,
- Enabled: true,
+ Name: apiModel,
+ Enabled: true,
}
- // Behavior params persist on Model (UI-facing) and are mirrored onto Chat
- // (runtime view). Env var names kept for backward compat.
if maxTokens := os.Getenv("SIYUAN_OPENAI_API_MAX_TOKENS"); "" != maxTokens {
if v, err := strconv.Atoi(maxTokens); err == nil {
- model.MaxTokens = v
ai.Chat.MaxCompletionTokens = v
}
}
if temperature := os.Getenv("SIYUAN_OPENAI_API_TEMPERATURE"); "" != temperature {
if v, err := strconv.ParseFloat(temperature, 64); err == nil {
- model.Temperature = v
ai.Chat.Temperature = v
}
}
if maxContexts := os.Getenv("SIYUAN_OPENAI_API_MAX_CONTEXTS"); "" != maxContexts {
if v, err := strconv.Atoi(maxContexts); err == nil {
- model.MaxContexts = v
ai.Chat.MaxHistoryMessages = v
ai.Chat.MaxContinueRounds = v
}
@@ -399,6 +389,14 @@ func MigrateAI(data []byte) *AI {
MaxRetries: getInt(oai, "agentMaxRetries"),
MaxToolCallRounds: 64,
}
+
+ maxContexts := getInt(oai, "apiMaxContexts")
+ ai.Chat = &Chat{
+ MaxHistoryMessages: maxContexts,
+ MaxContinueRounds: maxContexts,
+ Temperature: getFloat(oai, "apiTemperature"),
+ MaxCompletionTokens: getInt(oai, "apiMaxTokens"),
+ }
}
if provs, ok := raw["providers"].([]any); ok {
@@ -510,9 +508,6 @@ func migrateModel(raw map[string]any) *Model {
DisplayName: getString(raw, "name"),
Enabled: enabled,
Name: getString(raw, "apiModel"),
- MaxTokens: getInt(raw, "apiMaxTokens"),
- Temperature: getFloat(raw, "apiTemperature"),
- MaxContexts: getInt(raw, "apiMaxContexts"),
}
}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 0b54c1b15b..0a73ec6995 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -627,27 +627,8 @@ func InitConf() {
if "" == m.Name {
m.Name = openai.GPT3Dot5Turbo
}
- if 0 > m.MaxTokens {
- m.MaxTokens = 0
- }
- if 0 >= m.Temperature || 2 < m.Temperature {
- m.Temperature = 1.0
- }
- if 1 > m.MaxContexts || 64 < m.MaxContexts {
- m.MaxContexts = 7
- }
}
}
- // Chat is the runtime view of the chat-scenario model's behavior params.
- // The settings page still persists them on Model; mirror them onto Chat so
- // the chat runtime reads from a single, Agent-symmetric place.
- // https://github.com/siyuan-note/siyuan/issues/17797
- if prov, m := Conf.AI.GetScenarioModel(conf.ScenarioChat); nil != prov && nil != m {
- Conf.AI.Chat.MaxCompletionTokens = m.MaxTokens
- Conf.AI.Chat.Temperature = m.Temperature
- Conf.AI.Chat.MaxHistoryMessages = m.MaxContexts
- Conf.AI.Chat.MaxContinueRounds = m.MaxContexts
- }
if 0 > Conf.AI.Chat.MaxCompletionTokens {
Conf.AI.Chat.MaxCompletionTokens = 0
}