Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
open_ai_api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haojie
open_ai_api
Commits
9764c7f1
Commit
9764c7f1
authored
Apr 14, 2023
by
haojie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
865c9271
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
1 deletions
+89
-1
app/Http/Controllers/Api/User/TaskController.php
+35
-0
app/Service/TaskService.php
+49
-1
routes/api.php
+5
-0
No files found.
app/Http/Controllers/Api/User/TaskController.php
View file @
9764c7f1
...
...
@@ -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
)
...
...
app/Service/TaskService.php
View file @
9764c7f1
...
...
@@ -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
,
...
...
routes/api.php
View file @
9764c7f1
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment