Documentation
¶
Overview ¶
Package goba OneBot 11 协议 QQ 聊天 Agent
Index ¶
- Constants
- Variables
- type APIResponse
- type Agent
- func (ag *Agent) AddEvent(grp int64, ev *Event)
- func (ag *Agent) AddMemory(grp int64, text string) error
- func (ag *Agent) AddRequest(grp int64, req *zero.APIRequest)
- func (ag *Agent) AddResponse(grp int64, resp *APIResponse)
- func (ag *Agent) AddTerminus(grp int64)
- func (ag *Agent) CanViewImage() bool
- func (ag *Agent) ClearViewImageAPI()
- func (ag *Agent) GetAction(api deepinfra.API, p model.Protocol, grp int64, role PermRole, iter int, ...) (reqs []zero.APIRequest, err error)
- func (ag *Agent) LoadPermTable(file ...string) error
- func (ag *Agent) SetViewImageAPI(api deepinfra.API, p model.Protocol)
- type Config
- type Event
- type MemoryStorage
- type Perm
- type PermAction
- type PermRole
- type Terminus
Constants ¶
const ( // EOA is a dummy action that is used to terminate request EOA = "end_action" // SVM is a dummy action that is used to indicate that a memory has been saved SVM = "save_memory" )
Variables ¶
var ( // ErrNoSuchPermRole role 不在 config 记录中 ErrNoSuchPermRole = errors.New("no such perm role") // ErrUnexpectedAction 该 action 在 config 中找到但在 actions 中不存在 ErrUnexpectedAction = errors.New("unexpected action") )
var ( // ErrPermissionDenied LLM 调用了不该调用的 action ErrPermissionDenied = errors.New("permission denied") )
Functions ¶
This section is empty.
Types ¶
type APIResponse ¶
type APIResponse struct {
Status string `json:"status"`
Data json.RawMessage `json:"data"`
Message string `json:"message"`
Wording string `json:"wording"`
RetCode int64 `json:"retcode"`
}
APIResponse is the simplified OneBot response
func (*APIResponse) String ¶
func (resp *APIResponse) String() string
String dumps JSON without tailing \n
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is a OneBot event context, it is recommended to create one agent per group or per user.
func NewAgent ¶
func NewAgent( cfg *Config, batchcap, itemscap int, imgpcachettl time.Duration, defaultprompt string, mem MemoryStorage, manualaddreq, manualaddmem bool, ) (ag Agent)
NewAgent 创建一个 Agent 实例。
- characteristics 推荐使用 Markdown 格式,描述 Agent 个性。
- defaultprompt 为上下文为空时的默认提示,建议为事件的 JSON,一般不会用到,因此也可留空。
- manualaddreq 表示是否由用户手动添加请求。
- manualaddmem 表示是否由用户手动添加记忆。
func (*Agent) AddRequest ¶
func (ag *Agent) AddRequest(grp int64, req *zero.APIRequest)
AddRequest 添加 API 请求, 一般无需主动调用, 由 GetAction 自动添加
func (*Agent) AddResponse ¶
func (ag *Agent) AddResponse(grp int64, resp *APIResponse)
AddResponse 添加在执行完 zero.APIRequest 之后得到的响应
func (*Agent) AddTerminus ¶
AddTerminus 添加会话终止符, 一般无需主动调用, 由 GetAction 自动添加
func (*Agent) CanViewImage ¶
CanViewImage will be true if SetViewImageAPI is called
func (*Agent) GetAction ¶
func (ag *Agent) GetAction(api deepinfra.API, p model.Protocol, grp int64, role PermRole, iter int, isusersystem bool) ( reqs []zero.APIRequest, err error, )
GetAction get OneBot CallAction from LLM and add it to context.
Note:
- If LLM returns an invalid action, ErrPermissionDenied will be returned with complete reqs before invalid call, caller may decide whether to use these reqs by themselves. Whatever, invalid req will not be added into the context. You may call AddRequest to add it but it is not recommended.
func (*Agent) LoadPermTable ¶
LoadPermTable 读取 yaml file 并根据权限生成 MD 表格, 参数为空则加载内嵌配置
type Event ¶
type Event struct {
Time int64 `json:"time"` // 事件发生的时间戳
PostType string `json:"post_type"` // 上报类型: message / notice / request
MessageType string `json:"message_type"` // message 类型: group / private
SubType string `json:"sub_type,omitempty"` // message 子类型: normal (一般消息) / notice (灰色小字通知)
MessageID int64 `json:"message_id"` // 消息 ID, 唯一标识该事件
GroupID int64 `json:"group_id,omitempty"` // QQ群号
UserID int64 `json:"user_id"` // 事件发送者QQ号
TargetID int64 `json:"target_id,omitempty"`
SelfID int64 `json:"self_id"` // 收到事件的QQ号 (你的ID)
NoticeType string `json:"notice_type,omitempty"`
OperatorID int64 `json:"operator_id,omitempty"` // This field is used for Notice Event
File *zero.File `json:"file,omitempty"`
RequestType string `json:"request_type,omitempty"`
Flag string `json:"flag,omitempty"`
Comment string `json:"comment,omitempty"` // This field is used for Request Event
Sender *zero.User `json:"sender,omitempty"` // 事件发送者个人信息
Message json.RawMessage `json:"message,omitempty"` // JSON 格式的消息内容
}
Event is the simplified OneBot event that dumped to the agent in JSON format
type MemoryStorage ¶
MemoryStorage can be a db or just some files
type Perm ¶
type Perm struct {
Actions map[string]PermAction `yaml:"actions"`
Config map[PermRole][]string `yaml:"config"`
// contains filtered or unexported fields
}
Perm 即 actions.yaml 的 Go struct 映射
type PermAction ¶
type PermAction struct {
Desc string `yaml:"desc"`
Params string `yaml:"params"`
Data string `yaml:"data"`
}
PermAction 记录 action 的描述和 params