feat: plugin function is ready

This commit is contained in:
RockYang
2023-07-15 21:52:30 +08:00
parent d014d418e9
commit d8ff5987dd
9 changed files with 200 additions and 46 deletions

View File

@@ -2,6 +2,7 @@ package core
import (
"chatplus/core/types"
"chatplus/service/function"
"chatplus/store/model"
"chatplus/utils"
"chatplus/utils/resp"
@@ -30,9 +31,14 @@ type AppServer struct {
ChatSession *types.LMap[string, types.ChatSession] //map[sessionId]UserId
ChatClients *types.LMap[string, *types.WsClient] // map[sessionId]Websocket 连接集合
ReqCancelFunc *types.LMap[string, context.CancelFunc] // HttpClient 请求取消 handle function
Functions map[string]function.Function
}
func NewServer(appConfig *types.AppConfig) *AppServer {
func NewServer(
appConfig *types.AppConfig,
funZaoBao function.FuncZaoBao,
funZhiHu function.FuncHeadlines,
funWeibo function.FuncWeiboHot) *AppServer {
gin.SetMode(gin.ReleaseMode)
gin.DefaultWriter = io.Discard
return &AppServer{
@@ -43,6 +49,11 @@ func NewServer(appConfig *types.AppConfig) *AppServer {
ChatSession: types.NewLMap[string, types.ChatSession](),
ChatClients: types.NewLMap[string, *types.WsClient](),
ReqCancelFunc: types.NewLMap[string, context.CancelFunc](),
Functions: map[string]function.Function{
types.FuncZaoBao: funZaoBao,
types.FuncWeibo: funWeibo,
types.FuncHeadLine: funZhiHu,
},
}
}

View File

@@ -22,9 +22,15 @@ type Property struct {
Description string `json:"description"`
}
const (
FuncZaoBao = "zao_bao" // 每日早报
FuncHeadLine = "headline" // 今日头条
FuncWeibo = "weibo_hot" // 微博热搜
)
var InnerFunctions = []Function{
{
Name: "zao_bao",
Name: FuncZaoBao,
Description: "每日早报,获取当天全球的热门新闻事件列表",
Parameters: Parameters{
@@ -39,7 +45,7 @@ var InnerFunctions = []Function{
},
},
{
Name: "weibo_hot",
Name: FuncWeibo,
Description: "新浪微博热搜榜,微博当日热搜榜单",
Parameters: Parameters{
Type: "object",
@@ -54,8 +60,8 @@ var InnerFunctions = []Function{
},
{
Name: "zhihu_top",
Description: "知乎热榜,知乎当日话题讨论榜单",
Name: FuncHeadLine,
Description: "今日头条,给用户推荐当天的头条新闻,周榜热文",
Parameters: Parameters{
Type: "object",
Properties: map[string]Property{
@@ -68,9 +74,3 @@ var InnerFunctions = []Function{
},
},
}
var FunctionNameMap = map[string]string{
"zao_bao": "每日早报",
"weibo_hot": "微博热搜",
"zhihu_top": "知乎热榜",
}