diff --git a/consul/consul.go b/consul/consul.go index 7bf8b7c..b5e79cf 100644 --- a/consul/consul.go +++ b/consul/consul.go @@ -60,7 +60,7 @@ func getLocalIP() (string, error) { } func getInstanceAddrByIp(ctx context.Context, ip string, services []gsvc.Service) (addr string) { for _, s := range services { - if s.GetEndpoints()[0].Host() == addr { + if s.GetEndpoints()[0].Host() == ip { addr = s.GetEndpoints()[0].String() return } diff --git a/ragflow/document.go b/ragflow/document.go index 0d819a7..af39527 100644 --- a/ragflow/document.go +++ b/ragflow/document.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/frame/g" ) // 数据集内文件管理 @@ -201,16 +202,23 @@ func (c *Client) UploadDocumentFromText(ctx context.Context, datasetId, content, Data []UploadDocumentRes `json:"data"` // RAGFlow返回数组 } - if err := json.Unmarshal(resp.ReadAll(), &response); err != nil { + respBody := resp.ReadAll() + g.Log().Debugf(ctx, "RAGFlow上传文档响应: %s", string(respBody)) + + if err := json.Unmarshal(respBody, &response); err != nil { + g.Log().Errorf(ctx, "解析RAGFlow响应失败: %v, 原始响应: %s", err, string(respBody)) return "", gerror.Newf("json Decode failed: %v", err) } - if len(response.Data) == 0 { - return "", gerror.New("上传文档返回data为空") + // 先检查code,再检查data + if response.Code != 0 { + g.Log().Errorf(ctx, "RAGFlow返回错误: code=%d, message=%s", response.Code, response.Message) + return "", gerror.Newf("上传文档失败 (code=%d): %s", response.Code, response.Message) } - if response.Code != 0 { - return "", gerror.Newf("上传文档失败 (code=%d): %s", response.Code, response.Message) + if len(response.Data) == 0 { + g.Log().Errorf(ctx, "RAGFlow返回data为空, 完整响应: %s", string(respBody)) + return "", gerror.New("上传文档返回data为空") } return response.Data[0].Id, nil