add showdown

This commit is contained in:
root 2025-02-09 11:05:38 +08:00
parent 69951ada84
commit ba9fe9ef4b
4 changed files with 22 additions and 14 deletions

View File

@ -2,5 +2,6 @@ $content { padding:10px 20px; }
$content>div.message { padding:0px; overflow:auto; } $content>div.message { padding:0px; overflow:auto; }
$content>div.message>div.request { background-color:#94ec69; color:black; padding:10px; float:right; clear:both; } $content>div.message>div.request { background-color:#94ec69; color:black; padding:10px; float:right; clear:both; }
$content>div.message>div.request>span { float:right; } $content>div.message>div.request>span { float:right; }
$content>div.message>div.response { white-space:break-spaces; padding:0px; clear:both; } $content>div.message>div.response { padding:0px; clear:both; }
$content>div.message>div.response p { margin:5px 0; }
$content>div.request { padding-top:10px; } $content>div.request { padding-top:10px; }

View File

@ -15,11 +15,9 @@ type chat struct {
func (s chat) Request(m *ice.Message, arg ...string) { func (s chat) Request(m *ice.Message, arg ...string) {
m.Optionv(web.SPIDE_STREAM, func(text string) { web.PushNoticeGrow(m.Message, m.Option("which"), text) }) m.Optionv(web.SPIDE_STREAM, func(text string) { web.PushNoticeGrow(m.Message, m.Option("which"), text) })
m.Cmdy(web.SPIDE, ice.DEV, web.SPIDE_STREAM, http.MethodPost, "http://localhost:11434/api/chat", m.Cmdy(web.SPIDE, ice.DEV, web.SPIDE_STREAM, http.MethodPost, "http://localhost:11434/api/chat", web.SPIDE_DATA, kit.Format(kit.Dict(
web.SPIDE_DATA, kit.Format(kit.Dict("model", m.Option("model"), "stream", true, "model", m.Option("model"), "stream", true, "messages", kit.List(kit.Dict("role", "user", "content", arg[0])),
"messages", kit.List(kit.Dict("role", "user", "content", arg[0])), )))
)),
)
} }
func (s chat) List(m *ice.Message, arg ...string) { func (s chat) List(m *ice.Message, arg ...string) {
m.Cmdy(s.client).Display("").DisplayCSS("") m.Cmdy(s.client).Display("").DisplayCSS("")

View File

@ -1,15 +1,17 @@
Volcanos(chat.ONIMPORT, { Volcanos(chat.ONIMPORT, {
_init: function(can, msg) { can.ui = can.onappend.layout(can), can.ui.responseList = [] _init: function(can, msg) {
can.require(["https://unpkg.com/showdown/dist/showdown.min.js"])
can.ui = can.onappend.layout(can), can.ui.responseList = []
msg.Table(function(value) { can.onimport.item(can, { msg.Table(function(value) { can.onimport.item(can, {
name: value.NAME, nick: value.NAME+" ("+value.SIZE+")", name: value.NAME, nick: value.NAME+" ("+value.SIZE+")",
}, function(event, item, show, target) { }, function(event, item, show, target) {
can.onimport.tabsCache(can, item, target, function() { can.onimport.content(can, target) }) can.onimport.tabsCache(can, item, target, function() { can.onimport.content(can, target) })
can.db.model = item.name, can.ui.message = target._message can.db.model = item.name, can.ui.message = target.ui.message, can.ui.request = target.ui.request
can.onappend._status(can, msg), can.onimport.layout(can) can.onappend._status(can, msg), can.onimport.layout(can)
}) }) }) })
}, },
content: function(can, target) { content: function(can, target) {
var ui = can.page.Append(can, can.ui.content, [ target.ui = can.page.Append(can, can.ui.content, [
{view: "message", list: [ {view: "message", list: [
{view: "response", list: [ {view: "response", list: [
{text: can.user.trans(can, "Please Ask Anything!", "有什么问题尽管问吧!")}, {text: can.user.trans(can, "Please Ask Anything!", "有什么问题尽管问吧!")},
@ -22,21 +24,24 @@ Volcanos(chat.ONIMPORT, {
} }
}}, }},
]}, ]},
]); target._message = ui.message ])
}, },
_grow: function(can, msg, which, text) { _grow: function(can, msg, which, text) {
var target = can.ui.responseList[parseInt(which)-1], data = JSON.parse(text) var target = can.ui.responseList[parseInt(which)-1], data = JSON.parse(text)
can.page.Append(can, target, [{text: data.message.content}]), can.ui.message.scrollBy(0, 1000) if (window.showdown) { target._text = (target._text||"")+data.message.content
var converter = new showdown.Converter(); target.innerHTML = converter.makeHtml(target._text)
} else {
can.page.Append(can, target, [{text: data.message.content}])
} can.ui.message.scrollBy(0, 1000)
}, },
layout: function(can) { layout: function(can) {
can.ui.layout(can.ConfHeight(), can.ConfWidth(), 0, function() { can.ui.layout(can.ConfHeight(), can.ConfWidth(), 0, function() {
can.page.style(can, can.ui.message, html.MAX_HEIGHT, can.ConfHeight()-130) can.ui.request && can.page.style(can, can.ui.message, html.MAX_HEIGHT, can.ConfHeight()-can.ui.request.offsetHeight-20)
}) })
} }
}) })
Volcanos(chat.ONACTION, { Volcanos(chat.ONACTION, {
request: function(event, can, text) { request: function(event, can, text) { can.page.Append(can, can.ui.message, [{view: "request", list: [{text: text}]}])
can.page.Append(can, can.ui.message, [{view: "request", list: [{text: text}]}])
var response = can.page.Append(can, can.ui.message, [{view: "response"}])._target; can.ui.responseList.push(response) var response = can.page.Append(can, can.ui.message, [{view: "response"}])._target; can.ui.responseList.push(response)
can.request(event, {which: ""+can.ui.responseList.length, model: can.db.model}) can.request(event, {which: ""+can.ui.responseList.length, model: can.db.model})
can.runAction(event, "request", [text], function(msg) {}) can.runAction(event, "request", [text], function(msg) {})

View File

@ -19,4 +19,8 @@ refer `
通义千问 https://tongyi.aliyun.com/ 通义千问 https://tongyi.aliyun.com/
文心一言 https://yiyan.baidu.com/ 文心一言 https://yiyan.baidu.com/
月之暗面 https://kimi.moonshot.cn/ 月之暗面 https://kimi.moonshot.cn/
`
chapter "外部依赖"
refer `
https://github.com/showdownjs/showdown
` `