@@ -14,6 +14,7 @@ import (
1414 "github.com/wdvxdr1123/ZeroBot/message"
1515)
1616
17+ // AC is the global agent configuration
1718var AC AgentConfig
1819
1920var (
@@ -40,6 +41,7 @@ func (mt ModelType) String() string {
4041 return apilist [mt ]
4142}
4243
44+ // Protocol creates a protocol instance based on the model type
4345func (mt ModelType ) Protocol (modn string , temp float32 , topp float32 , maxn uint ) (mod model.Protocol , err error ) {
4446 switch AC .Type {
4547 case 0 :
@@ -87,6 +89,7 @@ func (mk ModelKey) String() string {
8789 return key [:2 ] + strings .Repeat ("*" , len (key )- 4 ) + key [len (key )- 2 :]
8890}
8991
92+ // AgentConfig holds the configuration for the chat agent
9093type AgentConfig struct {
9194 ModelName string
9295 ImageModelName string
@@ -144,7 +147,7 @@ func (c *AgentConfig) isvalid() bool {
144147 return c .Key != ""
145148}
146149
147- // 获取全局模型参数:TopP和最大长度
150+ // MParams returns the global model parameters: TopP and MaxN
148151func (c * AgentConfig ) MParams () (topp float32 , maxn uint ) {
149152 // 处理TopP参数
150153 topp = c .TopP
@@ -161,6 +164,7 @@ func (c *AgentConfig) MParams() (topp float32, maxn uint) {
161164 return topp , maxn
162165}
163166
167+ // EnsureConfig ensures the configuration is loaded and valid
164168func EnsureConfig (ctx * zero.Ctx ) bool {
165169 c , ok := ctx .State ["manager" ].(* ctrl.Control [* zero.Ctx ])
166170 if ! ok {
@@ -179,13 +183,10 @@ func EnsureConfig(ctx *zero.Ctx) bool {
179183 return true
180184}
181185
186+ // NewExtraSetStr creates a handler to set a string-based extra config value
182187func NewExtraSetStr [T ~ string ](ptr * T ) func (ctx * zero.Ctx ) {
183188 return func (ctx * zero.Ctx ) {
184189 args := strings .TrimSpace (ctx .State ["args" ].(string ))
185- if args == "" {
186- ctx .SendChain (message .Text ("ERROR: empty args" ))
187- return
188- }
189190 c , ok := ctx .State ["manager" ].(* ctrl.Control [* zero.Ctx ])
190191 if ! ok {
191192 ctx .SendChain (message .Text ("ERROR: no such plugin" ))
@@ -201,6 +202,7 @@ func NewExtraSetStr[T ~string](ptr *T) func(ctx *zero.Ctx) {
201202 }
202203}
203204
205+ // NewExtraSetBool creates a handler to set a boolean-based extra config value
204206func NewExtraSetBool [T ~ bool ](ptr * T ) func (ctx * zero.Ctx ) {
205207 return func (ctx * zero.Ctx ) {
206208 args := ctx .State ["regex_matched" ].([]string )
@@ -220,6 +222,7 @@ func NewExtraSetBool[T ~bool](ptr *T) func(ctx *zero.Ctx) {
220222 }
221223}
222224
225+ // NewExtraSetUint creates a handler to set a uint extra config value
223226func NewExtraSetUint (ptr * uint ) func (ctx * zero.Ctx ) {
224227 return func (ctx * zero.Ctx ) {
225228 args := strings .TrimSpace (ctx .State ["args" ].(string ))
@@ -247,6 +250,7 @@ func NewExtraSetUint(ptr *uint) func(ctx *zero.Ctx) {
247250 }
248251}
249252
253+ // NewExtraSetFloat32 creates a handler to set a float32 extra config value
250254func NewExtraSetFloat32 (ptr * float32 ) func (ctx * zero.Ctx ) {
251255 return func (ctx * zero.Ctx ) {
252256 args := strings .TrimSpace (ctx .State ["args" ].(string ))
@@ -274,6 +278,7 @@ func NewExtraSetFloat32(ptr *float32) func(ctx *zero.Ctx) {
274278 }
275279}
276280
281+ // NewExtraSetModelType creates a handler to set a ModelType extra config value
277282func NewExtraSetModelType (ptr * ModelType ) func (ctx * zero.Ctx ) {
278283 return func (ctx * zero.Ctx ) {
279284 args := strings .TrimSpace (ctx .State ["args" ].(string ))
0 commit comments