mirror of
https://shylinux.com/x/ollama-story
synced 2025-04-29 00:59:23 +08:00
add showdown
This commit is contained in:
parent
69951ada84
commit
ba9fe9ef4b
@ -2,5 +2,6 @@ $content { padding:10px 20px; }
|
||||
$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>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; }
|
@ -15,11 +15,9 @@ type chat struct {
|
||||
|
||||
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.Cmdy(web.SPIDE, ice.DEV, web.SPIDE_STREAM, http.MethodPost, "http://localhost:11434/api/chat",
|
||||
web.SPIDE_DATA, kit.Format(kit.Dict("model", m.Option("model"), "stream", true,
|
||||
"messages", kit.List(kit.Dict("role", "user", "content", arg[0])),
|
||||
)),
|
||||
)
|
||||
m.Cmdy(web.SPIDE, ice.DEV, web.SPIDE_STREAM, http.MethodPost, "http://localhost:11434/api/chat", web.SPIDE_DATA, kit.Format(kit.Dict(
|
||||
"model", m.Option("model"), "stream", true, "messages", kit.List(kit.Dict("role", "user", "content", arg[0])),
|
||||
)))
|
||||
}
|
||||
func (s chat) List(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(s.client).Display("").DisplayCSS("")
|
||||
|
@ -1,15 +1,17 @@
|
||||
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, {
|
||||
name: value.NAME, nick: value.NAME+" ("+value.SIZE+")",
|
||||
}, function(event, item, show, 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)
|
||||
}) })
|
||||
},
|
||||
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: "response", list: [
|
||||
{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) {
|
||||
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) {
|
||||
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, {
|
||||
request: function(event, can, text) {
|
||||
can.page.Append(can, can.ui.message, [{view: "request", list: [{text: text}]}])
|
||||
request: function(event, can, 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)
|
||||
can.request(event, {which: ""+can.ui.responseList.length, model: can.db.model})
|
||||
can.runAction(event, "request", [text], function(msg) {})
|
||||
|
@ -19,4 +19,8 @@ refer `
|
||||
通义千问 https://tongyi.aliyun.com/
|
||||
文心一言 https://yiyan.baidu.com/
|
||||
月之暗面 https://kimi.moonshot.cn/
|
||||
`
|
||||
chapter "外部依赖"
|
||||
refer `
|
||||
https://github.com/showdownjs/showdown
|
||||
`
|
Loading…
x
Reference in New Issue
Block a user