Commit 9764c7f1 by haojie

1

parent 865c9271
......@@ -38,6 +38,41 @@ public function apiSubmit(Request $request)
}
/**
* stable 提交任务
*/
public function stableSubmit(Request $request)
{
$data = $request->input();
$user = $request->user();
$result = app(TaskService::class)->stableSubmit($user->id, $data);
return $this->success('success', $result);
}
/**
* stable 获取任务
*
* @param Request $request
* @return mixed
*/
public function stableTask(Request $request)
{
$data = $request->input();
$result = app(TaskService::class)->getStableTask($data);
return $this->success('success', $result);
}
/**
* stable任务回调
*/
public function stableCallback(Request $request)
{
$data = $request->input();
$result = app(TaskService::class)->stableCallback($data);
return $this->success('success', $result);
}
/**
* python-gpt任务回调
*/
public function gpt_callback(Request $request)
......
......@@ -18,7 +18,7 @@ class TaskService
public const GPT_prompt_num = 1; // 指令数量
public const STATUS_WAIT = 0; // 等待
public const STATUS_SUCCESS = 1; // 成功
public const STATUS_FAIL = 2; // 失败
......@@ -183,6 +183,53 @@ public function stableSubmit(int $userId = 0, array $data = [])
];
}
/**
* stable 轮询获取stable任务
*/
public function getStableTask(array $data = [])
{
# 获取redis任务
$taskList = Redis::lpop('stable_task');
return $taskList;
}
/**
* stableCallback 回调
*/
public function stableCallback(array $data = [])
{
# 必须字段
$credentials = Arr::only($data, ['user_id', 'task_id', 'result_img', 'message', 'prompt_id', 'status']);
$user_id = $credentials['user_id'] ?? '';
$task_id = $credentials['task_id'] ?? '';
$prompt_id = $credentials['prompt_id'] ?? '';
$result_img = $credentials['result_img'] ?? '';
$message = $credentials['message'] ?? '';
$status = $credentials['status'] ?? '';
if (empty($task_id) || empty($prompt_id) || empty($user_id)) {
throw new UserException('缺少字段');
}
if ((int)$status == 2) {
# 任务失败
$task = PromptTask::find($prompt_id);
$sendData = [
'prompt' => $task->prompt,
'prompt_img' => $task->prompt_img,
'prompt_id' => $prompt_id,
'task_id' => $task->id,
'type' => $task->type,
];
# 提交redis
Redis::rpush('stable_task', json_encode($sendData));
} elseif ((int)$status == 1) {
# 任务成功
$task = PromptTask::find($prompt_id);
$task->result_img = $result_img;
$task->result_img_status = self::STATUS_SUCCESS;
$task->save();
}
}
/**
* redis队列插入--这是gpt生成指令的任务
......@@ -369,6 +416,7 @@ public function create_split_img_task(int $user_id = 0, $data = [])
# 更新
$prompt->update([
'cut_id' => $cut_id,
'cut_status' => self::STATUS_WAIT,
]);
$downloadData = [
'url' => $prompt->result_img,
......
......@@ -36,6 +36,10 @@
Route::get('config/policy2', 'ConfigController@policy');
# 图片切割回调接口
Route::post('split/callback', 'TaskController@split_callback');
# stable轮询获取任务
Route::get('stable/task', 'TaskController@stableTask');
# stable 回调
Route::post('stable/callback', 'TaskController@stableCallback');
});
// 需要登录
Route::group([
......@@ -57,6 +61,7 @@
Route::post('split', 'TaskController@split_img');
# 轮询请求切割后的图片地址
Route::get('split/status', 'TaskController@split_img_result');
});
});
# GPT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment