mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-23 16:56:10 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
7fdde53b5e
4 changed files with 50 additions and 16 deletions
|
|
@ -20,8 +20,10 @@ export const ai = {
|
|||
<select id="apiModel" class="b3-select">
|
||||
<option value="gpt-4" ${window.siyuan.config.ai.openAI.apiModel === "gpt-4" ? "selected" : ""}>gpt-4</option>
|
||||
<option value="gpt-4-32k" ${window.siyuan.config.ai.openAI.apiModel === "gpt-4-32k" ? "selected" : ""}>gpt-4-32k</option>
|
||||
<option value="gpt-4-1106-preview" ${window.siyuan.config.ai.openAI.apiModel === "gpt-4-1106-preview" ? "selected" : ""}>gpt-4-1106-preview</option>
|
||||
<option value="gpt-3.5-turbo" ${window.siyuan.config.ai.openAI.apiModel === "gpt-3.5-turbo" ? "selected" : ""}>gpt-3.5-turbo</option>
|
||||
<option value="gpt-3.5-turbo-16k" ${window.siyuan.config.ai.openAI.apiModel === "gpt-3.5-turbo-16k" ? "selected" : ""}>gpt-3.5-turbo-16k</option>
|
||||
<option value="gpt-3.5-turbo-1106" ${window.siyuan.config.ai.openAI.apiModel === "gpt-3.5-turbo-1106" ? "selected" : ""}>gpt-3.5-turbo-1106</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -67,8 +69,10 @@ export const ai = {
|
|||
<select id="apiModel" class="b3-select fn__flex-center fn__size200">
|
||||
<option value="gpt-4" ${window.siyuan.config.ai.openAI.apiModel === "gpt-4" ? "selected" : ""}>gpt-4</option>
|
||||
<option value="gpt-4-32k" ${window.siyuan.config.ai.openAI.apiModel === "gpt-4-32k" ? "selected" : ""}>gpt-4-32k</option>
|
||||
<option value="gpt-4-1106-preview" ${window.siyuan.config.ai.openAI.apiModel === "gpt-4-1106-preview" ? "selected" : ""}>gpt-4-1106-preview</option>
|
||||
<option value="gpt-3.5-turbo" ${window.siyuan.config.ai.openAI.apiModel === "gpt-3.5-turbo" ? "selected" : ""}>gpt-3.5-turbo</option>
|
||||
<option value="gpt-3.5-turbo-16k" ${window.siyuan.config.ai.openAI.apiModel === "gpt-3.5-turbo-16k" ? "selected" : ""}>gpt-3.5-turbo-16k</option>
|
||||
<option value="gpt-3.5-turbo-1106" ${window.siyuan.config.ai.openAI.apiModel === "gpt-3.5-turbo-1106" ? "selected" : ""}>gpt-3.5-turbo-1106</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="fn__flex b3-label">
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ require (
|
|||
github.com/panjf2000/ants/v2 v2.8.2
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/radovskyb/watcher v1.0.7
|
||||
github.com/rqlite/sql v0.0.0-20221103124402-8f9ff0ceb8f0
|
||||
github.com/sashabaranov/go-openai v1.17.6
|
||||
github.com/shirou/gopsutil/v3 v3.23.10
|
||||
github.com/siyuan-note/dejavu v0.0.0-20231114024923-42c60dc5343a
|
||||
|
|
|
|||
|
|
@ -146,6 +146,8 @@ github.com/go-resty/resty/v2 v2.10.0 h1:Qla4W/+TMmv0fOeeRqzEpXPLfTUnR5HZ1+lGs+Ck
|
|||
github.com/go-resty/resty/v2 v2.10.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A=
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
||||
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
|
||||
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
|
|
@ -335,6 +337,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
|
|||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/rqlite/sql v0.0.0-20221103124402-8f9ff0ceb8f0 h1:C8DZB5okjhCSd7zvkOM+zxGz7S6ulUFIL34bpkqFk+0=
|
||||
github.com/rqlite/sql v0.0.0-20221103124402-8f9ff0ceb8f0/go.mod h1:ib9zVtNgRKiGuoMyUqqL5aNpk+r+++YlyiVIkclVqPg=
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
|
||||
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
|
||||
github.com/sashabaranov/go-openai v1.17.6 h1:hYXRPM1xO6QLOJhWEOMlSg/l3jERiKDKd1qIoK22lvs=
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/vitess-sqlparser/sqlparser"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
sqlparser2 "github.com/rqlite/sql"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -384,24 +385,48 @@ func QueryNoLimit(stmt string) (ret []map[string]interface{}, err error) {
|
|||
}
|
||||
|
||||
func Query(stmt string, limit int) (ret []map[string]interface{}, err error) {
|
||||
parsedStmt, err := sqlparser.Parse(stmt)
|
||||
// Kernel API `/api/query/sql` support `||` operator https://github.com/siyuan-note/siyuan/issues/9662
|
||||
// 这里为了支持 || 操作符,使用了另一个 sql 解析器,但是这个解析器无法处理 UNION https://github.com/siyuan-note/siyuan/issues/8226
|
||||
// 考虑到 UNION 的使用场景不多,这里还是以支持 || 操作符为主
|
||||
p := sqlparser2.NewParser(strings.NewReader(stmt))
|
||||
parsedStmt2, err := p.ParseStatement()
|
||||
if nil != err {
|
||||
return queryRawStmt(stmt, limit)
|
||||
}
|
||||
if !strings.Contains(stmt, "||") {
|
||||
// 这个解析器无法处理 || 连接字符串操作符
|
||||
parsedStmt, err2 := sqlparser.Parse(stmt)
|
||||
if nil != err2 {
|
||||
return queryRawStmt(stmt, limit)
|
||||
}
|
||||
|
||||
switch parsedStmt.(type) {
|
||||
case *sqlparser.Select:
|
||||
limitClause := getLimitClause(parsedStmt, limit)
|
||||
slct := parsedStmt.(*sqlparser.Select)
|
||||
slct.Limit = limitClause
|
||||
stmt = sqlparser.String(slct)
|
||||
case *sqlparser.Union:
|
||||
limitClause := getLimitClause(parsedStmt, limit)
|
||||
union := parsedStmt.(*sqlparser.Union)
|
||||
union.Limit = limitClause
|
||||
stmt = sqlparser.String(union)
|
||||
default:
|
||||
return queryRawStmt(stmt, limit)
|
||||
switch parsedStmt.(type) {
|
||||
case *sqlparser.Select:
|
||||
limitClause := getLimitClause(parsedStmt, limit)
|
||||
slct := parsedStmt.(*sqlparser.Select)
|
||||
slct.Limit = limitClause
|
||||
stmt = sqlparser.String(slct)
|
||||
case *sqlparser.Union:
|
||||
// Kernel API `/api/query/sql` support `UNION` statement https://github.com/siyuan-note/siyuan/issues/8226
|
||||
limitClause := getLimitClause(parsedStmt, limit)
|
||||
union := parsedStmt.(*sqlparser.Union)
|
||||
union.Limit = limitClause
|
||||
stmt = sqlparser.String(union)
|
||||
default:
|
||||
return queryRawStmt(stmt, limit)
|
||||
}
|
||||
} else {
|
||||
return queryRawStmt(stmt, limit)
|
||||
}
|
||||
} else {
|
||||
switch parsedStmt2.(type) {
|
||||
case *sqlparser2.SelectStatement:
|
||||
slct := parsedStmt2.(*sqlparser2.SelectStatement)
|
||||
if nil == slct.LimitExpr {
|
||||
slct.LimitExpr = &sqlparser2.NumberLit{Value: strconv.Itoa(limit)}
|
||||
}
|
||||
stmt = slct.String()
|
||||
default:
|
||||
return queryRawStmt(stmt, limit)
|
||||
}
|
||||
}
|
||||
|
||||
ret = []map[string]interface{}{}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue