Signed-off-by: jagger <cossjie@foxmail.com>
Former-commit-id: 04902084af
pull/252/head
| @@ -1818,4 +1818,12 @@ service AICore-api { | |||||
| get /getVisualizationJob (GetVisualizationJobReq) returns (GetVisualizationJobResp) | get /getVisualizationJob (GetVisualizationJobReq) returns (GetVisualizationJobResp) | ||||
| @handler createVisualizationJobHandler | @handler createVisualizationJobHandler | ||||
| post /CreateVisualizationJob (CreateVisualizationJobReq) returns (CreateVisualizationJobResp) | post /CreateVisualizationJob (CreateVisualizationJobReq) returns (CreateVisualizationJobResp) | ||||
| }*/ | |||||
| }*/ | |||||
| type ( | |||||
| ChatReq{ | |||||
| ApiUrl string `json:"apiUrl,optional"` | |||||
| Method string `json:"method,optional"` | |||||
| ReqData map[string]interface{} `json:"reqData"` | |||||
| } | |||||
| ) | |||||
| @@ -1256,5 +1256,14 @@ type ( | |||||
| ClusterName string `json:"clusterName" db:"cluster_name"` | ClusterName string `json:"clusterName" db:"cluster_name"` | ||||
| Status string `json:"status" db:"status"` | Status string `json:"status" db:"status"` | ||||
| Remark string `json:"remark" db:"remark"` | Remark string `json:"remark" db:"remark"` | ||||
| InferUrl string `json:"inferUrl"` | |||||
| } | |||||
| ) | |||||
| type ( | |||||
| CommonResp { | |||||
| Code int `json:"code,omitempty"` | |||||
| Msg string `json:"msg,omitempty"` | |||||
| Data interface{} `json:"data,omitempty"` | |||||
| } | } | ||||
| ) | ) | ||||
| @@ -366,6 +366,12 @@ service pcm { | |||||
| @handler createVisualizationJobHandler | @handler createVisualizationJobHandler | ||||
| post /ai/CreateVisualizationJob (CreateVisualizationJobReq) returns (CreateVisualizationJobResp) | post /ai/CreateVisualizationJob (CreateVisualizationJobReq) returns (CreateVisualizationJobResp) | ||||
| /******************Visualization Job Method start*************************/ | /******************Visualization Job Method start*************************/ | ||||
| /***********chat***********/ | |||||
| @doc "文本识别" | |||||
| @handler ProxyApiHandler | |||||
| post /ai/chat (ChatReq) returns (CommonResp) | |||||
| /******chat end***********/ | |||||
| } | } | ||||
| //screen接口 | //screen接口 | ||||
| @@ -0,0 +1,24 @@ | |||||
| package ai | |||||
| import ( | |||||
| "github.com/zeromicro/go-zero/rest/httpx" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/ai" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | |||||
| "net/http" | |||||
| ) | |||||
| func ProxyApiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||
| return func(w http.ResponseWriter, r *http.Request) { | |||||
| var req types.ChatReq | |||||
| if err := httpx.Parse(r, &req); err != nil { | |||||
| result.ParamErrorResult(r, w, err) | |||||
| return | |||||
| } | |||||
| l := ai.NewProxyApiLogic(r.Context(), svcCtx) | |||||
| resp, err := l.ProxyApi(&req, w) | |||||
| result.HttpResult(r, w, resp, err) | |||||
| } | |||||
| } | |||||
| @@ -437,6 +437,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||||
| Path: "/ai/CreateVisualizationJob", | Path: "/ai/CreateVisualizationJob", | ||||
| Handler: ai.CreateVisualizationJobHandler(serverCtx), | Handler: ai.CreateVisualizationJobHandler(serverCtx), | ||||
| }, | }, | ||||
| { | |||||
| Method: http.MethodPost, | |||||
| Path: "/ai/chat", | |||||
| Handler: ai.ProxyApiHandler(serverCtx), | |||||
| }, | |||||
| }, | }, | ||||
| rest.WithPrefix("/pcm/v1"), | rest.WithPrefix("/pcm/v1"), | ||||
| ) | ) | ||||
| @@ -0,0 +1,56 @@ | |||||
| package ai | |||||
| import ( | |||||
| "bytes" | |||||
| "context" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" | |||||
| tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" | |||||
| "k8s.io/apimachinery/pkg/util/json" | |||||
| "net/http" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" | |||||
| "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" | |||||
| "github.com/zeromicro/go-zero/core/logx" | |||||
| ) | |||||
| type ProxyApiLogic struct { | |||||
| logx.Logger | |||||
| ctx context.Context | |||||
| svcCtx *svc.ServiceContext | |||||
| } | |||||
| func NewProxyApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProxyApiLogic { | |||||
| return &ProxyApiLogic{ | |||||
| Logger: logx.WithContext(ctx), | |||||
| ctx: ctx, | |||||
| svcCtx: svcCtx, | |||||
| } | |||||
| } | |||||
| type ChatResult struct { | |||||
| Results string `json:"results"` | |||||
| } | |||||
| func (l *ProxyApiLogic) ProxyApi(req *types.ChatReq, w http.ResponseWriter) (resp *types.CommonResp, err error) { | |||||
| jsonBytes, err := json.Marshal(&req.ReqData) | |||||
| // 调用第三方接口的 POST 方法 | |||||
| respThirdParty, err := http.Post(req.ApiUrl, "application/json", bytes.NewBuffer(jsonBytes)) | |||||
| if err != nil { | |||||
| return | |||||
| } | |||||
| defer respThirdParty.Body.Close() | |||||
| marshal, err := json.Marshal(&respThirdParty.Body) | |||||
| if err != nil { | |||||
| return nil, result.NewDefaultError(err.Error()) | |||||
| } | |||||
| json.Unmarshal(marshal, &resp) | |||||
| chatResult := &ChatResult{} | |||||
| tool.Convert(resp, &chatResult.Results) | |||||
| return &types.CommonResp{ | |||||
| Code: respThirdParty.StatusCode, | |||||
| Msg: "success", | |||||
| Data: chatResult, | |||||
| }, nil | |||||
| } | |||||
| @@ -1179,6 +1179,13 @@ type SubTaskInfo struct { | |||||
| ClusterName string `json:"clusterName" db:"cluster_name"` | ClusterName string `json:"clusterName" db:"cluster_name"` | ||||
| Status string `json:"status" db:"status"` | Status string `json:"status" db:"status"` | ||||
| Remark string `json:"remark" db:"remark"` | Remark string `json:"remark" db:"remark"` | ||||
| InferUrl string `json:"inferUrl"` | |||||
| } | |||||
| type CommonResp struct { | |||||
| Code int `json:"code,omitempty"` | |||||
| Msg string `json:"msg,omitempty"` | |||||
| Data interface{} `json:"data,omitempty"` | |||||
| } | } | ||||
| type CommitHpcTaskReq struct { | type CommitHpcTaskReq struct { | ||||
| @@ -2869,6 +2876,12 @@ type AiTask struct { | |||||
| TimeElapsed int32 `json:"elapsed,optional"` | TimeElapsed int32 `json:"elapsed,optional"` | ||||
| } | } | ||||
| type ChatReq struct { | |||||
| ApiUrl string `json:"apiUrl,optional"` | |||||
| Method string `json:"method,optional"` | |||||
| ReqData map[string]interface{} `json:"reqData"` | |||||
| } | |||||
| type StorageScreenReq struct { | type StorageScreenReq struct { | ||||
| } | } | ||||