将各个判断模型是否可用的逻辑和接口/api/v1/initialization/ollama/models/check的逻辑统一:对于没有指定版本的模型,默认添加":latest",避免误判导致反复调用pull模型接口

This commit is contained in:
fuyaozong
2025-11-12 18:36:21 +08:00
committed by lyingbug
parent 07c3453e1a
commit ef69e2aed5
2 changed files with 7 additions and 6 deletions

View File

@@ -556,11 +556,7 @@ func (h *InitializationHandler) CheckOllamaModels(c *gin.Context) {
// 检查每个模型是否存在
for _, modelName := range req.Models {
checkModelName := modelName
if !strings.Contains(modelName, ":") {
checkModelName = modelName + ":latest"
}
available, err := h.ollamaService.IsModelAvailable(ctx, checkModelName)
available, err := h.ollamaService.IsModelAvailable(ctx, modelName)
if err != nil {
logger.ErrorWithFields(ctx, err, map[string]interface{}{
"model_name": modelName,

View File

@@ -107,9 +107,14 @@ func (s *OllamaService) IsModelAvailable(ctx context.Context, modelName string)
return false, fmt.Errorf("failed to get model list: %w", err)
}
// If no version is specified for the model, add ":latest" by default
checkModelName := modelName
if !strings.Contains(modelName, ":") {
checkModelName = modelName + ":latest"
}
// Check if model is in the list
for _, model := range listResp.Models {
if model.Name == modelName {
if model.Name == checkModelName {
return true, nil
}
}