pcm-modelarts/internal/logic/modelartsservice/imagereasoninglogic.go

46 lines
1.2 KiB
Go

package modelartsservicelogic
import (
"bytes"
"context"
"gitlink.org.cn/JointCloud/pcm-modelarts/internal/util"
"k8s.io/apimachinery/pkg/util/json"
"gitlink.org.cn/JointCloud/pcm-modelarts/internal/svc"
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
"github.com/zeromicro/go-zero/core/logx"
)
type ImageReasoningLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewImageReasoningLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ImageReasoningLogic {
return &ImageReasoningLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// reasoning
func (l *ImageReasoningLogic) ImageReasoning(in *modelarts.ImageReasoningReq) (*modelarts.ImageReasoningResp, error) {
// todo: add your logic here and delete this line
var resp modelarts.ImageReasoningResp
platform, err := util.GetModelArtsConfWithPlatform(in.Platform)
if err != nil {
return nil, err
}
reqByte, err := json.Marshal(in)
body, err := util.SendRequest("POST", platform.Endpoint+"v1/infers/"+in.ServiceId+"/image",
bytes.NewBuffer(reqByte), in.Platform)
if err != nil {
return nil, err
}
json.Unmarshal(*body, &resp)
return &resp, nil
}