mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-11 22:25:41 +08:00
fix: include user model settings in /user/me response (#15320)
### What problem does this PR solve? Fixes the `/user/me` response so it returns the current user's model settings correctly. ### Type of change - Added model settings data to the `/user/me` response. - Kept the response structure compatible with existing user profile fields. - Avoided changing unrelated user/session behavior.
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
|
||||
"ragflow/internal/service"
|
||||
)
|
||||
@@ -545,22 +546,63 @@ func (h *UserHandler) SetTenantInfo(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var req service.SetTenantInfoRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
requiredKeys := []string{"tenant_id", "asr_id", "embd_id", "img2txt_id", "llm_id"}
|
||||
missingArgumentMessage := "required argument are missing: tenant_id,asr_id,embd_id,img2txt_id,llm_id; "
|
||||
|
||||
var payload map[string]interface{}
|
||||
if err := c.ShouldBindBodyWith(&payload, binding.JSON); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeArgumentError,
|
||||
"message": err.Error(),
|
||||
"data": false,
|
||||
"message": missingArgumentMessage,
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
err := h.userService.SetTenantInfo(user.ID, &req)
|
||||
missing := make([]string, 0, len(requiredKeys))
|
||||
for _, key := range requiredKeys {
|
||||
if _, ok := payload[key]; !ok {
|
||||
missing = append(missing, key)
|
||||
}
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeArgumentError,
|
||||
"message": fmt.Sprintf("required argument are missing: %s; ", joinStrings(missing)),
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
req := service.SetTenantInfoRequest{Raw: payload}
|
||||
if value, ok := payload["tenant_id"].(string); ok {
|
||||
req.TenantID = &value
|
||||
}
|
||||
if value, ok := payload["asr_id"].(string); ok {
|
||||
req.ASRID = &value
|
||||
}
|
||||
if value, ok := payload["embd_id"].(string); ok {
|
||||
req.EmbdID = &value
|
||||
}
|
||||
if value, ok := payload["img2txt_id"].(string); ok {
|
||||
req.Img2TxtID = &value
|
||||
}
|
||||
if value, ok := payload["llm_id"].(string); ok {
|
||||
req.LLMID = &value
|
||||
}
|
||||
if value, ok := payload["rerank_id"].(string); ok {
|
||||
req.RerankID = &value
|
||||
}
|
||||
if value, ok := payload["tts_id"].(string); ok {
|
||||
req.TTSID = &value
|
||||
}
|
||||
|
||||
code, err := h.userService.SetTenantInfo(user.ID, &req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": common.CodeDataError,
|
||||
"code": code,
|
||||
"message": err.Error(),
|
||||
"data": false,
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -571,3 +613,14 @@ func (h *UserHandler) SetTenantInfo(c *gin.Context) {
|
||||
"data": true,
|
||||
})
|
||||
}
|
||||
|
||||
func joinStrings(values []string) string {
|
||||
if len(values) == 0 {
|
||||
return ""
|
||||
}
|
||||
result := values[0]
|
||||
for i := 1; i < len(values); i++ {
|
||||
result += "," + values[i]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user