prompts-core
This commit is contained in:
54
service/http_service.go
Normal file
54
service/http_service.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
commonHttp "gitea.com/red-future/common/http"
|
||||
)
|
||||
|
||||
// ============================================
|
||||
// model-gateway 网关交互
|
||||
// ============================================
|
||||
|
||||
// CreateTaskReq 创建任务请求
|
||||
type CreateTaskReq struct {
|
||||
TaskId string `json:"task_id"`
|
||||
State int `json:"state"`
|
||||
OssFile string `json:"oss_file"`
|
||||
FileType string `json:"file_type"`
|
||||
Text string `json:"text"`
|
||||
ErrorMsg string `json:"error_msg"`
|
||||
}
|
||||
|
||||
// createGatewayTask 调用 model-gateway 异步任务并同步等待结果
|
||||
func createGatewayTask(ctx context.Context, payload map[string]any) (string, error) {
|
||||
fullURL := "model-gateway/task/createTask"
|
||||
headers := forwardHeaders(ctx)
|
||||
var req CreateTaskReq
|
||||
body, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := commonHttp.Post(ctx, fullURL, headers, &req, body); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return req.TaskId, nil
|
||||
}
|
||||
|
||||
type GetTaskResultRes struct {
|
||||
OssFile string `json:"ossFile" dc:"结果文件OSS地址"`
|
||||
State int `json:"state" dc:"任务状态"`
|
||||
}
|
||||
|
||||
// queryGatewayTaskState 查询网关任务状态
|
||||
func queryGatewayTaskState(ctx context.Context, taskID string) (int, error) {
|
||||
fullURL := fmt.Sprintf("model-gateway/task/getTaskResult?taskId=%s", taskID)
|
||||
headers := forwardHeaders(ctx)
|
||||
var req GetTaskResultRes
|
||||
if err := commonHttp.Get(ctx, fullURL, headers, &req, nil); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return req.State, nil
|
||||
}
|
||||
Reference in New Issue
Block a user