This commit is contained in:
root 2025-02-08 12:02:46 +08:00
parent ef64b388d9
commit 0229267387
6 changed files with 81 additions and 7 deletions

5
src/client/chat.css Normal file
View File

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

27
src/client/chat.go Normal file
View File

@ -0,0 +1,27 @@
package client
import (
"net/http"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
)
type chat struct {
list string `name:"list name auto" help:"大模型对话"`
}
func (s chat) Request(m *ice.Message, arg ...string) {
m.Optionv(web.SPIDE_STREAM, func(text string) { web.PushNoticeGrow(m.Message, 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", "deepseek-r1", "stream", true,
"messages", kit.List(kit.Dict("role", "user", "content", arg[0])),
)),
)
}
func (s chat) List(m *ice.Message, arg ...string) {
m.Display("").DisplayCSS("")
}
func init() { ice.CodeModCmd(chat{}) }

28
src/client/chat.js Normal file
View File

@ -0,0 +1,28 @@
Volcanos(chat.ONIMPORT, {
_init: function(can, msg) {
can.ui = can.page.Append(can, can._output, [
{view: "message"},
{view: "request", list: [
{type: "textarea", onkeydown: function(event) {
if (event.key == "Enter") {
can.onaction.request(event, can, event.target.value), event.target.value = "", can.onkeymap.prevent(event)
}
}},
]},
])
can.ui.response = can.page.Append(can, can.ui.message, [{view: "response", list: [{text: "有什么问题尽管问吧!"}]}])._target
},
_grow: function(can, msg, text) { var data = JSON.parse(text)
can.page.Append(can, can.ui.response, [{text: data.message.content}]), can.ui.message.scrollBy(0, 1000)
},
layout: function(can) {
can.page.style(can, can.ui.message, html.MAX_HEIGHT, can.ConfHeight()-140)
}
})
Volcanos(chat.ONACTION, {
request: function(event, can, text) {
can.page.Append(can, can.ui.message, [{view: "request", list: [{text: text}]}])
can.ui.response = can.page.Append(can, can.ui.message, [{view: "response"}])._target
can.runAction(event, "request", [text], function(msg) {})
},
})

View File

@ -1,15 +1,23 @@
package client package client
import "shylinux.com/x/ice" import (
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/cli"
)
type client struct { type client struct {
ice.Hash list string `name:"list NAME auto" help:"大模型"`
list string `name:"list hash auto" help:"client"`
} }
func (s client) List(m *ice.Message, arg ...string) { func (s client) List(m *ice.Message, arg ...string) {
s.Hash.List(m, arg...) if len(arg) == 0 {
m.SplitIndex(s.cmdx(m, "list"))
} else if len(arg) == 1 {
m.Echo(s.cmdx(m, "show", arg[0]))
}
}
func (s client) cmdx(m *ice.Message, arg ...string) string {
return m.Cmdx(cli.SYSTEM, "ollama", arg)
} }
func init() { ice.Cmd("web.chat.client.client", client{}) } func init() { ice.Cmd("web.chat.ollama.client", client{}) }

View File

@ -12,4 +12,4 @@ func (s server) List(m *ice.Message, arg ...string) {
s.Hash.List(m, arg...) s.Hash.List(m, arg...)
} }
func init() { ice.Cmd("web.chat.server.server", server{}) } func init() { ice.Cmd("web.chat.ollama.server", server{}) }

6
src/server/server.shy Normal file
View File

@ -0,0 +1,6 @@
title "ollama"
refer `
官网 https://ollama.com/
源码 https://github.com/ollama/ollama
简介 https://blog.csdn.net/qq_40999403/article/details/139320266
`