mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-29 12:09:31 +08:00
Go: add context, part12 (#17435)
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -78,7 +78,8 @@ func (h *DatasetsHandler) ListDatasets(c *gin.Context) {
|
||||
}
|
||||
|
||||
if c.Query("type") == "filter" {
|
||||
data, code, err := h.datasetsService.ListDatasetFilters(user.ID)
|
||||
ctx := c.Request.Context()
|
||||
data, code, err := h.datasetsService.ListDatasetFilters(ctx, user.ID)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, code, err.Error())
|
||||
return
|
||||
|
||||
@@ -836,7 +836,7 @@ func (h *DocumentHandler) UploadDocuments(c *gin.Context) {
|
||||
common.ResponseWithCodeData(c, common.CodeDataError, nil, fmt.Sprintf("Can't find the dataset with ID %s!", datasetID))
|
||||
return
|
||||
}
|
||||
if !h.datasetService.CheckKBTeamPermission(kb, tenantID) {
|
||||
if !h.datasetService.CheckKBTeamPermission(ctx, kb, tenantID) {
|
||||
common.ResponseWithCodeData(c, common.CodeAuthenticationError, nil, "No authorization.")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -20,14 +20,13 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ragflow/internal/common"
|
||||
"ragflow/internal/entity"
|
||||
modelModule "ragflow/internal/entity/models"
|
||||
"ragflow/internal/service"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type mindMapRunConfig struct {
|
||||
@@ -64,18 +63,19 @@ func runMindMap(ctx context.Context, config mindMapRunConfig) (mindMapNode, erro
|
||||
}
|
||||
modelID, _ := config.SearchConfig["chat_id"].(string)
|
||||
messages := []modelModule.Message{{Role: "system", Content: mindMapPrompt(strings.Join(sections, "\n"))}, {Role: "user", Content: "Output:"}}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
streamCtx, streamCancel := context.WithTimeout(ctx, 10*time.Minute)
|
||||
defer streamCancel()
|
||||
|
||||
// search_config chat_id can be a stale tenant_model ID that no longer
|
||||
// exists. ResolveModelConfig tries ID lookup first, then falls back to
|
||||
// composite-name parsing which fails for bare IDs. If the configured
|
||||
// model can't be resolved, fall back to the tenant's default chat model
|
||||
// (mirrors Python's gen_mindmap get_tenant_default_model_by_type).
|
||||
ch, streamErr := config.LLM.ChatStream(ctx, modelTenantID, modelID, messages, &modelModule.ChatConfig{})
|
||||
ch, streamErr := config.LLM.ChatStream(streamCtx, modelTenantID, modelID, messages, &modelModule.ChatConfig{})
|
||||
if streamErr != nil && config.TenantSvc != nil {
|
||||
if defaultModel, err := config.TenantSvc.GetDefaultModelName(modelTenantID, entity.ModelTypeChat); err == nil && defaultModel != "" && defaultModel != modelID {
|
||||
ch, streamErr = config.LLM.ChatStream(ctx, modelTenantID, defaultModel, messages, &modelModule.ChatConfig{})
|
||||
if defaultModel, err := config.TenantSvc.GetDefaultModelName(streamCtx, modelTenantID, entity.ModelTypeChat); err == nil && defaultModel != "" && defaultModel != modelID {
|
||||
ch, streamErr = config.LLM.ChatStream(streamCtx, modelTenantID, defaultModel, messages, &modelModule.ChatConfig{})
|
||||
}
|
||||
}
|
||||
if streamErr != nil {
|
||||
|
||||
@@ -1425,8 +1425,9 @@ func (h *ProviderHandler) ListTenantAddedModels(c *gin.Context) {
|
||||
|
||||
modelType := c.Query("type")
|
||||
ownerTenantID := c.Query("owner_tenant_id")
|
||||
ctx := c.Request.Context()
|
||||
|
||||
addedModels, code, err := h.modelProviderService.ListTenantAddedModels(user.ID, ownerTenantID, modelType)
|
||||
addedModels, code, err := h.modelProviderService.ListTenantAddedModels(ctx, user.ID, ownerTenantID, modelType)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, code, err.Error())
|
||||
return
|
||||
|
||||
@@ -260,7 +260,8 @@ func (h *SearchBotHandler) Ask(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
if modelID == "" && h.tenantSvc != nil {
|
||||
defaultModel, err := h.tenantSvc.GetDefaultModelName(user.ID, entity.ModelTypeChat)
|
||||
ctx := c.Request.Context()
|
||||
defaultModel, err := h.tenantSvc.GetDefaultModelName(ctx, user.ID, entity.ModelTypeChat)
|
||||
if err == nil && defaultModel != "" {
|
||||
modelID = defaultModel
|
||||
}
|
||||
|
||||
@@ -75,7 +75,8 @@ func (h *TenantHandler) setDefaultModels(c *gin.Context, wrapModels bool) {
|
||||
return
|
||||
}
|
||||
|
||||
err := h.tenantService.SetTenantDefaultModels(user.ID, req.ModelProvider, req.ModelInstance, req.ModelName, req.ModelType, req.ModelID)
|
||||
ctx := c.Request.Context()
|
||||
err := h.tenantService.SetTenantDefaultModels(ctx, user.ID, req.ModelProvider, req.ModelInstance, req.ModelName, req.ModelType, req.ModelID)
|
||||
if err != nil {
|
||||
common.ResponseWithCodeData(c, common.CodeExceptionError, false, err.Error())
|
||||
return
|
||||
@@ -100,8 +101,9 @@ func (h *TenantHandler) GetDefaultModels(c *gin.Context) {
|
||||
common.ErrorWithCode(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
|
||||
defaultModels, err := h.tenantService.ListTenantDefaultModels(user.ID)
|
||||
defaultModels, err := h.tenantService.ListTenantDefaultModels(ctx, user.ID)
|
||||
if err != nil {
|
||||
common.ResponseWithCodeData(c, common.CodeExceptionError, false, err.Error())
|
||||
return
|
||||
@@ -132,8 +134,9 @@ func (h *TenantHandler) TenantInfo(c *gin.Context) {
|
||||
common.ErrorWithCode(c, errorCode, errorMessage)
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
|
||||
tenantInfo, err := h.tenantService.GetTenantInfo(user.ID)
|
||||
tenantInfo, err := h.tenantService.GetTenantInfo(ctx, user.ID)
|
||||
if err != nil {
|
||||
common.ResponseWithCodeData(c, common.CodeExceptionError, false, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user