🎨 AI supports configuration randomness and context number https://github.com/siyuan-note/siyuan/issues/10660

This commit is contained in:
Daniel 2024-03-20 11:45:22 +08:00
parent 41b4984de3
commit 5300638622
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
11 changed files with 55 additions and 10 deletions

View file

@ -84,8 +84,8 @@ func chatGPTContinueWrite(msg string, contextMsgs []string, cloud bool) (ret str
util.PushEndlessProgress("Requesting...")
defer util.ClearPushProgress(100)
if 7 < len(contextMsgs) {
contextMsgs = contextMsgs[len(contextMsgs)-7:]
if Conf.AI.OpenAI.APIMaxContexts < len(contextMsgs) {
contextMsgs = contextMsgs[len(contextMsgs)-Conf.AI.OpenAI.APIMaxContexts:]
}
var gpt GPT
@ -96,7 +96,7 @@ func chatGPTContinueWrite(msg string, contextMsgs []string, cloud bool) (ret str
}
buf := &bytes.Buffer{}
for i := 0; i < 7; i++ {
for i := 0; i < Conf.AI.OpenAI.APIMaxContexts; i++ {
part, stop, chatErr := gpt.chat(msg, contextMsgs)
buf.WriteString(part)

View file

@ -420,6 +420,9 @@ func InitConf() {
if 0 >= Conf.AI.OpenAI.APITemperature || 2 < Conf.AI.OpenAI.APITemperature {
Conf.AI.OpenAI.APITemperature = 1.0
}
if 1 > Conf.AI.OpenAI.APIMaxContexts || 64 < Conf.AI.OpenAI.APIMaxContexts {
Conf.AI.OpenAI.APIMaxContexts = 7
}
if "" != Conf.AI.OpenAI.APIKey {
logging.LogInfof("OpenAI API enabled\n"+
@ -429,14 +432,16 @@ func InitConf() {
" proxy=%s\n"+
" model=%s\n"+
" maxTokens=%d\n"+
" temperature=%.1f",
" temperature=%.1f\n"+
" maxContexts=%d",
Conf.AI.OpenAI.APIUserAgent,
Conf.AI.OpenAI.APIBaseURL,
Conf.AI.OpenAI.APITimeout,
Conf.AI.OpenAI.APIProxy,
Conf.AI.OpenAI.APIModel,
Conf.AI.OpenAI.APIMaxTokens,
Conf.AI.OpenAI.APITemperature)
Conf.AI.OpenAI.APITemperature,
Conf.AI.OpenAI.APIMaxContexts)
}
Conf.ReadOnly = util.ReadOnly