fix: ai deploy bug

This commit is contained in:
Liujian
2025-02-17 00:37:25 +08:00
parent 35b25289bd
commit 94d5ed0773
14 changed files with 227 additions and 44 deletions
+15 -22
View File
@@ -3,15 +3,12 @@ package ai_local
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"math"
"net/http"
"strings"
"gorm.io/gorm"
"github.com/APIParkLab/APIPark/module/router"
"github.com/APIParkLab/APIPark/model/plugin_model"
@@ -100,13 +97,13 @@ func (i *imlLocalModelController) Deploy(ctx *gin.Context) {
return
}
err = i.initAILocalService(ctx, input.Model, input.Team)
if err != nil {
ctx.JSON(200, gin.H{
"code": -1, "msg": err.Error(), "success": "fail",
})
return
}
//err = i.initAILocalService(ctx, input.Model, input.Team)
//if err != nil {
// ctx.JSON(200, gin.H{
// "code": -1, "msg": err.Error(), "success": "fail",
// })
// return
//}
id := uuid.NewString()
p, err := i.module.Deploy(ctx, input.Model, id)
if err != nil {
@@ -199,23 +196,15 @@ func (i *imlLocalModelController) DeployStart(ctx *gin.Context, input *ai_local_
func (i *imlLocalModelController) initAILocalService(ctx context.Context, model string, teamID string) error {
err := i.transaction.Transaction(ctx, func(ctx context.Context) error {
_, err := i.serviceModule.Get(ctx, model)
if err == nil {
return nil
} else {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return err
}
}
catalogueInfo, err := i.catalogueModule.DefaultCatalogue(ctx)
if err != nil {
return err
}
serviceId := uuid.NewString()
prefix := fmt.Sprintf("/%s", serviceId[:8])
providerId := "ollama"
prefix := strings.Replace("/"+model, ":", "_", -1)
info, err := i.serviceModule.Create(ctx, teamID, &service_dto.CreateService{
Id: model,
Id: serviceId,
Name: model,
Prefix: prefix,
Description: "Auto generated service for AI model " + model,
@@ -229,6 +218,10 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model
if err != nil {
return err
}
err = i.module.SaveCache(ctx, model, serviceId)
if err != nil {
return err
}
path := fmt.Sprintf("/%s/chat", strings.Trim(prefix, "/"))
timeout := 300000
retry := 0
@@ -244,7 +237,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model
}
name := "Demo AI API"
description := "A demo that shows you how to use a e a Chat API."
apiId := uuid.New().String()
apiId := uuid.NewString()
err = i.aiAPIModule.Create(
ctx,
info.Id,