Merge pull request #508 from trheyi/main
[add] sui build IgnoreDocument support & neo local model support
This commit is contained in:
commit
3a44464f3b
7 changed files with 60 additions and 33 deletions
|
|
@ -27,10 +27,10 @@ func NewOpenAI(data []byte) *JSON {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := makeMessage()
|
msg := makeMessage()
|
||||||
data = []byte(strings.TrimPrefix(string(data), "data: "))
|
text := string(data)
|
||||||
|
data = []byte(strings.TrimPrefix(text, "data: "))
|
||||||
switch {
|
switch {
|
||||||
|
case strings.Contains(text, `"delta":{`) && strings.Contains(text, `"content":`):
|
||||||
case strings.Contains(string(data), `"delta":{"content"`):
|
|
||||||
var message openai.Message
|
var message openai.Message
|
||||||
err := jsoniter.Unmarshal(data, &message)
|
err := jsoniter.Unmarshal(data, &message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -43,12 +43,12 @@ func NewOpenAI(data []byte) *JSON {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case strings.Contains(string(data), `[DONE]`):
|
case strings.Contains(text, `[DONE]`):
|
||||||
msg.Done = true
|
msg.Done = true
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
msg.Error = string(data)
|
msg.Error = text
|
||||||
}
|
}
|
||||||
|
|
||||||
return &JSON{msg}
|
return &JSON{msg}
|
||||||
|
|
|
||||||
44
neo/neo.go
44
neo/neo.go
|
|
@ -257,32 +257,32 @@ func (neo *DSL) Answer(ctx command.Context, question string, answer Answer) erro
|
||||||
|
|
||||||
return !msg.IsDone()
|
return !msg.IsDone()
|
||||||
|
|
||||||
case <-ctx.Done():
|
// case <-ctx.Done():
|
||||||
if err := ctx.Err(); err != nil {
|
// if err := ctx.Err(); err != nil {
|
||||||
message.New().Text(err.Error()).Write(w)
|
// message.New().Text(err.Error()).Write(w)
|
||||||
}
|
// }
|
||||||
|
|
||||||
if len(errorMsg) > 0 {
|
// if len(errorMsg) > 0 {
|
||||||
|
|
||||||
var errData openai.ErrorMessage
|
// var errData openai.ErrorMessage
|
||||||
err := jsoniter.Unmarshal(errorMsg, &errData)
|
// err := jsoniter.Unmarshal(errorMsg, &errData)
|
||||||
if err == nil {
|
// if err == nil {
|
||||||
msg := errData.Error.Message
|
// msg := errData.Error.Message
|
||||||
if msg == "" {
|
// if msg == "" {
|
||||||
msg = fmt.Sprintf("OpenAI error: %s", errData.Error.Code)
|
// msg = fmt.Sprintf("OpenAI error: %s", errData.Error.Code)
|
||||||
}
|
// }
|
||||||
message.New().Text(msg).Write(w)
|
// message.New().Text(msg).Write(w)
|
||||||
message.New().Done().Write(w)
|
// message.New().Done().Write(w)
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
|
|
||||||
message.New().Text(string(errorMsg)).Write(w)
|
// message.New().Text(string(errorMsg)).Write(w)
|
||||||
message.New().Done().Write(w)
|
// message.New().Done().Write(w)
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
|
|
||||||
message.New().Done().Write(w)
|
// message.New().Done().Write(w)
|
||||||
return false
|
// return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,14 @@ func (page *Page) Build(option *BuildOption) (*goquery.Document, []string, error
|
||||||
// BuildHTML build the html
|
// BuildHTML build the html
|
||||||
func (page *Page) BuildHTML(option *BuildOption) (string, error) {
|
func (page *Page) BuildHTML(option *BuildOption) (string, error) {
|
||||||
|
|
||||||
html := string(page.Document)
|
html := string(page.Codes.HTML.Code)
|
||||||
|
|
||||||
|
if !option.IgnoreDocument {
|
||||||
|
html = string(page.Document)
|
||||||
if page.Codes.HTML.Code != "" {
|
if page.Codes.HTML.Code != "" {
|
||||||
html = strings.Replace(html, "{{ __page }}", page.Codes.HTML.Code, 1)
|
html = strings.Replace(html, "{{ __page }}", page.Codes.HTML.Code, 1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !option.IgnoreAssetRoot {
|
if !option.IgnoreAssetRoot {
|
||||||
html = strings.ReplaceAll(html, "@assets", option.AssetRoot)
|
html = strings.ReplaceAll(html, "@assets", option.AssetRoot)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ func (page *Page) EditorRender() (*ResponseEditorRender, error) {
|
||||||
doc, warnings, err := page.Build(&BuildOption{
|
doc, warnings, err := page.Build(&BuildOption{
|
||||||
SSR: true,
|
SSR: true,
|
||||||
IgnoreAssetRoot: true,
|
IgnoreAssetRoot: true,
|
||||||
|
IgnoreDocument: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -72,10 +72,28 @@ func testPage(t *testing.T) *Page {
|
||||||
<div>{{ idx }} {{ article.title }}</div>
|
<div>{{ idx }} {{ article.title }}</div>
|
||||||
<div>{{ article.desc }}</div>
|
<div>{{ article.desc }}</div>
|
||||||
<div>{{ article.type == "article" ? "article" : "others"}}</div>
|
<div>{{ article.type == "article" ? "article" : "others"}}</div>
|
||||||
|
|
||||||
|
<div class="mt-10">IF</div>
|
||||||
|
<div class="p-5">
|
||||||
<div s:if="article.type == 'article'">article</div>
|
<div s:if="article.type == 'article'">article</div>
|
||||||
<div s:elif="article.type == 'image'">image</div>
|
<div s:elif="article.type == 'image'">image</div>
|
||||||
<div s:else>others</div>
|
<div s:else>others</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-10">Nested</div>
|
||||||
|
<div
|
||||||
|
s:for="article.images"
|
||||||
|
s:for-item="image"
|
||||||
|
s:for-index="imgIndex"
|
||||||
|
class="p-5"
|
||||||
|
>
|
||||||
|
<div s:if="imgIndex == 1 || imgIndex == 2" class="p-5">
|
||||||
|
{{ imgIndex }} {{ image }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
<div class="mt-10">IF</div>
|
<div class="mt-10">IF</div>
|
||||||
<div s:if="len(articles) > 0" :name="input.data">
|
<div s:if="len(articles) > 0" :name="input.data">
|
||||||
<div>{{ len(articles) > 0 }} articles.length > 0</div>
|
<div>{{ len(articles) > 0 }} articles.length > 0</div>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/yaoapp/kun/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRender(t *testing.T) {
|
func TestRender(t *testing.T) {
|
||||||
|
|
@ -29,6 +30,8 @@ func TestRender(t *testing.T) {
|
||||||
t.Fatalf("Render error: %v", err)
|
t.Fatalf("Render error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.Dump(html)
|
||||||
|
|
||||||
assert.NotEmpty(t, html)
|
assert.NotEmpty(t, html)
|
||||||
assert.Contains(t, html, "hello space")
|
assert.Contains(t, html, "hello space")
|
||||||
assert.Equal(t, 0, len(parser.errors))
|
assert.Equal(t, 0, len(parser.errors))
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ type BuildOption struct {
|
||||||
UpdateAll bool `json:"update_all"`
|
UpdateAll bool `json:"update_all"`
|
||||||
AssetRoot string `json:"asset_root,omitempty"`
|
AssetRoot string `json:"asset_root,omitempty"`
|
||||||
IgnoreAssetRoot bool `json:"ignore_asset_root,omitempty"`
|
IgnoreAssetRoot bool `json:"ignore_asset_root,omitempty"`
|
||||||
|
IgnoreDocument bool `json:"ignore_document,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request is the struct for the request
|
// Request is the struct for the request
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue