新增 TakeBusinessFields、WriteBusinessFields、SetByPath 与 GetByPath 等工具,支持按映射路径写入请求体与解析响应,并更新相关依赖。
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
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
|
|
}
|