diff --git a/neo/message/json.go b/neo/message/json.go index 199d2ffa..1f152896 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 0d546599..6c8dbc28 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) - } + // case <-ctx.Done(): + // if err := ctx.Err(); err != nil { + // message.New().Text(err.Error()).Write(w) + // } - if len(errorMsg) > 0 { + // 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 - } + // 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().Text(string(errorMsg)).Write(w) + // message.New().Done().Write(w) + // return false + // } - message.New().Done().Write(w) - return false + // message.New().Done().Write(w) + // return false } }) diff --git a/sui/core/build.go b/sui/core/build.go index f9dbfdf2..f9740285 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 baf1737d..78c94023 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/page_test.go b/sui/core/page_test.go index 45f18ac0..ad7b9f76 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 61279cec..1727879f 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)) diff --git a/sui/core/types.go b/sui/core/types.go index c5ffa742..4c396548 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