1
0
mirror of https://github.com/fumiama/go-onebot-agent.git synced 2026-06-09 04:30:09 +08:00

feat: add more apis & handle resp

This commit is contained in:
源文雨
2025-09-25 23:02:09 +08:00
parent 0cdc929590
commit 46ace7c2b1
7 changed files with 257 additions and 23 deletions

View File

@@ -60,6 +60,11 @@ func (ag *Agent) AddRequest(grp int64, req *zero.APIRequest) {
ag.log.Add(grp, req, true)
}
// AddRequest 添加在执行完 zero.APIRequest 之后得到的响应
func (ag *Agent) AddResponse(grp int64, resp *APIResponse) {
ag.log.Add(grp, resp, false)
}
// CanViewImage will be true if SetViewImageAPI is called
func (ag *Agent) CanViewImage() bool {
return ag.hasimageapi
@@ -130,6 +135,11 @@ func (ag *Agent) GetAction(api deepinfra.API, p model.Protocol, grp int64, role
if err != nil {
return
}
if strings.HasPrefix(resp, "```") { // AI returns codeblock
_, resp, _ = strings.Cut(resp, "\n")
resp = strings.Trim(resp, "`")
resp = strings.TrimSpace(resp)
}
reqs = make([]zero.APIRequest, 0, 2)
dec := json.NewDecoder(strings.NewReader(resp))
dec.UseNumber()