mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-01 02:10:15 +01:00
🎨 AI supports configuration randomness and context number https://github.com/siyuan-note/siyuan/issues/10660
This commit is contained in:
parent
41b4984de3
commit
5300638622
11 changed files with 55 additions and 10 deletions
|
|
@ -198,6 +198,10 @@ func setAI(c *gin.Context) {
|
|||
ai.OpenAI.APITemperature = 1.0
|
||||
}
|
||||
|
||||
if 1 > ai.OpenAI.APIMaxContexts || 64 < ai.OpenAI.APIMaxContexts {
|
||||
ai.OpenAI.APIMaxContexts = 7
|
||||
}
|
||||
|
||||
model.Conf.AI = ai
|
||||
model.Conf.Save()
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type OpenAI struct {
|
|||
APIModel string `json:"apiModel"`
|
||||
APIMaxTokens int `json:"apiMaxTokens"`
|
||||
APITemperature float64 `json:"apiTemperature"`
|
||||
APIMaxContexts int `json:"apiMaxContexts"`
|
||||
APIBaseURL string `json:"apiBaseURL"`
|
||||
APIUserAgent string `json:"apiUserAgent"`
|
||||
APIProvider string `json:"apiProvider"` // OpenAI, Azure
|
||||
|
|
@ -43,11 +44,13 @@ type OpenAI struct {
|
|||
|
||||
func NewAI() *AI {
|
||||
openAI := &OpenAI{
|
||||
APITimeout: 30,
|
||||
APIModel: openai.GPT3Dot5Turbo,
|
||||
APIBaseURL: "https://api.openai.com/v1",
|
||||
APIUserAgent: util.UserAgent,
|
||||
APIProvider: "OpenAI",
|
||||
APITemperature: 1.0,
|
||||
APIMaxContexts: 7,
|
||||
APITimeout: 30,
|
||||
APIModel: openai.GPT3Dot5Turbo,
|
||||
APIBaseURL: "https://api.openai.com/v1",
|
||||
APIUserAgent: util.UserAgent,
|
||||
APIProvider: "OpenAI",
|
||||
}
|
||||
|
||||
openAI.APIKey = os.Getenv("SIYUAN_OPENAI_API_KEY")
|
||||
|
|
@ -77,6 +80,13 @@ func NewAI() *AI {
|
|||
}
|
||||
}
|
||||
|
||||
if maxContexts := os.Getenv("SIYUAN_OPENAI_API_MAX_CONTEXTS"); "" != maxContexts {
|
||||
maxContextsInt, err := strconv.Atoi(maxContexts)
|
||||
if nil == err {
|
||||
openAI.APIMaxContexts = maxContextsInt
|
||||
}
|
||||
}
|
||||
|
||||
if baseURL := os.Getenv("SIYUAN_OPENAI_API_BASE_URL"); "" != baseURL {
|
||||
openAI.APIBaseURL = baseURL
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue