重构了一下 rag的方法, 使用 goframe的框架, 还有redis连接部分
This commit is contained in:
@@ -2,7 +2,8 @@ package ragflow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
// 聊天助手管理
|
||||
@@ -104,7 +105,7 @@ func (c *Client) CreateChat(ctx context.Context, req *CreateChatReq) (*Chat, err
|
||||
return nil, err
|
||||
}
|
||||
if res.Code != 0 {
|
||||
return nil, fmt.Errorf("create chat failed: %s", res.Msg)
|
||||
return nil, gerror.Newf("create chat failed: %s", res.Msg)
|
||||
}
|
||||
return res.Data, nil
|
||||
}
|
||||
@@ -144,33 +145,33 @@ func (c *Client) ListChats(ctx context.Context, req *ListChatsReq) (*ListChatsRe
|
||||
return nil, err
|
||||
}
|
||||
if res.Code != 0 {
|
||||
return nil, fmt.Errorf("list chats failed: code=%d", res.Code)
|
||||
return nil, gerror.Newf("list chats failed: code=%d", res.Code)
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// DeleteChats 删除聊天助手
|
||||
func (c *Client) DeleteChats(ctx context.Context, ids []string) error {
|
||||
func (c *Client) DeleteChats(ctx context.Context, ids []string) (err error) {
|
||||
req := DeleteChatsReq{Ids: ids}
|
||||
var res CommonResponse
|
||||
if err := c.request(ctx, "DELETE", "/api/v1/chats", req, &res); err != nil {
|
||||
return err
|
||||
if err = c.request(ctx, "DELETE", "/api/v1/chats", req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if !res.IsSuccess() {
|
||||
return fmt.Errorf("delete chats failed: %s", res.Message)
|
||||
return gerror.Newf("delete chats failed: %s", res.Message)
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateChat 更新聊天助手
|
||||
func (c *Client) UpdateChat(ctx context.Context, id string, req *UpdateChatReq) error {
|
||||
func (c *Client) UpdateChat(ctx context.Context, id string, req *UpdateChatReq) (err error) {
|
||||
var res CommonResponse
|
||||
path := fmt.Sprintf("/api/v1/chats/%s", id)
|
||||
if err := c.request(ctx, "PUT", path, req, &res); err != nil {
|
||||
return err
|
||||
path := "/api/v1/chats/" + id
|
||||
if err = c.request(ctx, "PUT", path, req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
if !res.IsSuccess() {
|
||||
return fmt.Errorf("update chat failed: %s", res.Message)
|
||||
return gerror.Newf("update chat failed: %s", res.Message)
|
||||
}
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user