package controller import ( "context" "encoding/json" "model-gateway/model/dto" "model-gateway/service" "net/http" "gitea.redpowerfuture.com/red-future/common/beans" "github.com/gogf/gf/v2/frame/g" ) // ModelCall 模型调用控制器 var ModelCall = new(modelCall) type modelCall struct{} // ModelCall 模型调用 func (c *modelCall) ModelCall(ctx context.Context, req *dto.ModelCallReq) (res *dto.ModelCallRes, err error) { return service.ModelCall.ModelCall(ctx, req) } // CreateSessionStream 创建模型会话(流式) func (c *modelCall) CreateSessionStream(ctx context.Context, req *dto.ModelCallStreamReq) (res *beans.ResponseEmpty, err error) { r := g.RequestFromCtx(ctx) w := r.Response.RawWriter() err = service.ModelCall.ModelCallStream(ctx, w, req) if err != nil { h := w.Header() h.Set("Content-Type", "application/json; charset=utf-8") errResp, _ := json.Marshal(map[string]interface{}{ "code": http.StatusInternalServerError, "message": err.Error(), }) w.WriteHeader(http.StatusInternalServerError) _, _ = w.Write(errResp) } return }