@@ -10,6 +10,7 @@ import (
1010
1111 "github.com/fumiama/deepinfra"
1212 "github.com/fumiama/deepinfra/model"
13+ goba "github.com/fumiama/go-onebot-agent"
1314 "github.com/sirupsen/logrus"
1415 "github.com/tidwall/gjson"
1516
3334 Help : "- 设置AI聊天触发概率10\n " +
3435 "- 设置AI聊天温度80\n " +
3536 "- 设置AI聊天接口类型[OpenAI|OLLaMA|GenAI]\n " +
37+ "- 设置AI聊天(不)使用Agent模式\n " +
3638 "- 设置AI聊天(不)支持系统提示词\n " +
3739 "- 设置AI聊天接口地址https://api.siliconflow.cn/v1/chat/completions\n " +
3840 "- 设置AI聊天密钥xxx\n " +
@@ -142,6 +144,24 @@ func init() {
142144 return
143145 }
144146
147+ if ! cfg .NoAgent {
148+ role := goba .PermRoleUser
149+ if zero .AdminPermission (ctx ) {
150+ role = goba .PermRoleAdmin
151+ if zero .SuperUserPermission (ctx ) {
152+ role = goba .PermRoleOwner
153+ }
154+ }
155+ req , err := chat .AgentOf (ctx .Event .SelfID ).GetAction (x , mod , gid , role , false )
156+ if err != nil {
157+ logrus .Warnln ("[aichat] agent err:" , err , & req )
158+ return
159+ }
160+ logrus .Infoln ("[aichat] agent do:" , & req )
161+ ctx .CallAction (req .Action , req .Params )
162+ return
163+ }
164+
145165 data , err := x .Request (chat .GetChatContext (mod , gid , cfg .SystemP , cfg .NoSystemP ))
146166 if err != nil {
147167 logrus .Warnln ("[aichat] post err:" , err )
@@ -150,7 +170,7 @@ func init() {
150170
151171 txt := chat .Sanitize (strings .Trim (data , "\n " ))
152172 if len (txt ) > 0 {
153- chat .AddChatReply (gid , zero . BotConfig . NickName [ 0 ], txt )
173+ chat .AddChatReply (gid , txt )
154174 nick := zero .BotConfig .NickName [rand .Intn (len (zero .BotConfig .NickName ))]
155175 txt = strings .ReplaceAll (txt , "{name}" , ctx .CardOrNickName (ctx .Event .UserID ))
156176 txt = strings .ReplaceAll (txt , "{me}" , nick )
@@ -302,6 +322,8 @@ func init() {
302322 Handle (newextrasetbool (& cfg .NoReplyAT ))
303323 en .OnRegex ("^设置AI聊天(不)?支持系统提示词$" , ensureconfig , zero .OnlyPrivate , zero .SuperUserPermission ).SetBlock (true ).
304324 Handle (newextrasetbool (& cfg .NoSystemP ))
325+ en .OnRegex ("^设置AI聊天(不)?使用Agent模式$" , ensureconfig , zero .OnlyPrivate , zero .SuperUserPermission ).SetBlock (true ).
326+ Handle (newextrasetbool (& cfg .NoAgent ))
305327 en .OnPrefix ("设置AI聊天最大长度" , ensureconfig , zero .OnlyPrivate , zero .SuperUserPermission ).SetBlock (true ).
306328 Handle (newextrasetuint (& cfg .MaxN ))
307329 en .OnPrefix ("设置AI聊天TopP" , ensureconfig , zero .OnlyPrivate , zero .SuperUserPermission ).SetBlock (true ).
0 commit comments