From 4015573f5b38bb8550c6b82d376573ea727012eb Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Nov 2023 20:50:01 +0800 Subject: [PATCH 1/3] [_] --- sui/core/page_test.go | 24 +++++++++++++++++++++--- sui/core/parser_test.go | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sui/core/page_test.go b/sui/core/page_test.go index 45f18ac0d..ad7b9f76d 100644 --- a/sui/core/page_test.go +++ b/sui/core/page_test.go @@ -72,9 +72,27 @@ func testPage(t *testing.T) *Page {
{{ idx }} {{ article.title }}
{{ article.desc }}
{{ article.type == "article" ? "article" : "others"}}
-
article
-
image
-
others
+ +
IF
+
+
article
+
image
+
others
+
+ +
Nested
+
+
+ {{ imgIndex }} {{ image }} +
+
+ +
IF
diff --git a/sui/core/parser_test.go b/sui/core/parser_test.go index 61279cecd..1727879f9 100644 --- a/sui/core/parser_test.go +++ b/sui/core/parser_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/yaoapp/kun/utils" ) func TestRender(t *testing.T) { @@ -29,6 +30,8 @@ func TestRender(t *testing.T) { t.Fatalf("Render error: %v", err) } + utils.Dump(html) + assert.NotEmpty(t, html) assert.Contains(t, html, "hello space") assert.Equal(t, 0, len(parser.errors)) From 46b20bb778d7a65eacc1a6c0f5aebcfc90697a31 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 29 Nov 2023 21:29:44 +0800 Subject: [PATCH 2/3] [add] sui build IgnoreDocument support --- sui/core/build.go | 10 +++++++--- sui/core/editor.go | 1 + sui/core/types.go | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sui/core/build.go b/sui/core/build.go index f9dbfdf26..f97402855 100644 --- a/sui/core/build.go +++ b/sui/core/build.go @@ -41,9 +41,13 @@ func (page *Page) Build(option *BuildOption) (*goquery.Document, []string, error // BuildHTML build the html func (page *Page) BuildHTML(option *BuildOption) (string, error) { - html := string(page.Document) - if page.Codes.HTML.Code != "" { - html = strings.Replace(html, "{{ __page }}", page.Codes.HTML.Code, 1) + html := string(page.Codes.HTML.Code) + + if !option.IgnoreDocument { + html = string(page.Document) + if page.Codes.HTML.Code != "" { + html = strings.Replace(html, "{{ __page }}", page.Codes.HTML.Code, 1) + } } if !option.IgnoreAssetRoot { diff --git a/sui/core/editor.go b/sui/core/editor.go index baf1737d9..78c94023a 100644 --- a/sui/core/editor.go +++ b/sui/core/editor.go @@ -42,6 +42,7 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) { doc, warnings, err := page.Build(&BuildOption{ SSR: true, IgnoreAssetRoot: true, + IgnoreDocument: true, }) if err != nil { diff --git a/sui/core/types.go b/sui/core/types.go index c5ffa7427..4c3965483 100644 --- a/sui/core/types.go +++ b/sui/core/types.go @@ -140,6 +140,7 @@ type BuildOption struct { UpdateAll bool `json:"update_all"` AssetRoot string `json:"asset_root,omitempty"` IgnoreAssetRoot bool `json:"ignore_asset_root,omitempty"` + IgnoreDocument bool `json:"ignore_document,omitempty"` } // Request is the struct for the request From 59dfe49302aaef1d5918e8049a7d3381953f9ddb Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 1 Dec 2023 00:05:57 +0800 Subject: [PATCH 3/3] [add] neo local model support --- neo/message/json.go | 10 ++++----- neo/neo.go | 52 ++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/neo/message/json.go b/neo/message/json.go index 199d2ffa8..1f1528967 100644 --- a/neo/message/json.go +++ b/neo/message/json.go @@ -27,10 +27,10 @@ func NewOpenAI(data []byte) *JSON { } msg := makeMessage() - data = []byte(strings.TrimPrefix(string(data), "data: ")) + text := string(data) + data = []byte(strings.TrimPrefix(text, "data: ")) switch { - - case strings.Contains(string(data), `"delta":{"content"`): + case strings.Contains(text, `"delta":{`) && strings.Contains(text, `"content":`): var message openai.Message err := jsoniter.Unmarshal(data, &message) if err != nil { @@ -43,12 +43,12 @@ func NewOpenAI(data []byte) *JSON { } break - case strings.Contains(string(data), `[DONE]`): + case strings.Contains(text, `[DONE]`): msg.Done = true break default: - msg.Error = string(data) + msg.Error = text } return &JSON{msg} diff --git a/neo/neo.go b/neo/neo.go index 0d5465993..6c8dbc285 100644 --- a/neo/neo.go +++ b/neo/neo.go @@ -257,32 +257,32 @@ func (neo *DSL) Answer(ctx command.Context, question string, answer Answer) erro return !msg.IsDone() - case <-ctx.Done(): - if err := ctx.Err(); err != nil { - message.New().Text(err.Error()).Write(w) - } - - if len(errorMsg) > 0 { - - var errData openai.ErrorMessage - err := jsoniter.Unmarshal(errorMsg, &errData) - if err == nil { - msg := errData.Error.Message - if msg == "" { - msg = fmt.Sprintf("OpenAI error: %s", errData.Error.Code) - } - message.New().Text(msg).Write(w) - message.New().Done().Write(w) - return false - } - - message.New().Text(string(errorMsg)).Write(w) - message.New().Done().Write(w) - return false - } - - message.New().Done().Write(w) - return false + // case <-ctx.Done(): + // if err := ctx.Err(); err != nil { + // message.New().Text(err.Error()).Write(w) + // } + + // if len(errorMsg) > 0 { + + // var errData openai.ErrorMessage + // err := jsoniter.Unmarshal(errorMsg, &errData) + // if err == nil { + // msg := errData.Error.Message + // if msg == "" { + // msg = fmt.Sprintf("OpenAI error: %s", errData.Error.Code) + // } + // message.New().Text(msg).Write(w) + // message.New().Done().Write(w) + // return false + // } + + // message.New().Text(string(errorMsg)).Write(w) + // message.New().Done().Write(w) + // return false + // } + + // message.New().Done().Write(w) + // return false } })